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 trialAlejandro Byrne
2,562 PointsWhy does my code not work?
I'm supposed to make a function called "just_right" that returns "Your string is too long!" or "Your string is too short!" depending on wether the string is more or less than 5 characters long. If it is 5 - or, else - then just return True
def just_right(asd):
if len(asd) < 5:
return("Your string is too short")
elif len(asd) < 5:
return("Your string is too long")
else:
return(True)
1 Answer
Steven Parker
231,271 PointsYou may just have a typo.
On line 4, did you mean to write this:
elif len(asd) < 5:
I'm guessing that you actually meant to write this instead:
elif len(asd) > 5:
Alejandro Byrne
2,562 PointsOh wow, that was so dumb of me! Thanks anyway, it worked!
joshthorn
30,751 Pointsjoshthorn
30,751 PointsIn your elif, you say to return if the string is less than 5. The symbol < means less than, for more than use >.
So, for your elif, the code would be: