Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMark Kohner
1,121 PointsPython basics number game , str length
Create a new function just_right, accepts a string as an argument, <5 chart print too short, >5 chart print too long, else true.
def just_right(str(a)): if len(a) < 5: return 'Your string is too short' elif: return 'Your string is too long' else: return True
I am just getting an error 'bummer!' syntax error: def just_right(str(a))
I originally tried def just_right(''): if len ('') <5:
with same results, and 'a'. I do not know what is meant to go here, and the error is not helpful.
def just_right(str(a)):
if len(a) < 5:
return 'Your string is too short'
elif:
return 'Your string is too long'
else:
return True
1 Answer
jcorum
71,830 PointsMark, two issues: (1) elif needs a condition, and (2) the function's argument needs to be just a variable:
def just_right(str): //argument needs to be just a variable
if len(str) < 5:
return 'Your string is too short'
elif len(str) > 5: //needs a condition
return 'Your string is too long'
else:
return True