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 trialAli S
2,605 PointsI think I have an indentation mistake or some other kind of mistake but no clue what it is.
Create a new function named just_right that takes a single argument, a string. If the length of the string is less than five characters, return "Your string is too short". If the string is longer than five characters, return "Your string is too long". Otherwise, just return True.
Thank you in advance
def just_right(argument):
if len(argument) > 5:
return ("Your sting is too short")
elif len(argument) < 5:
return ("Your string is too long")
else:
return True
2 Answers
andren
28,558 PointsYour indentation is actually fine. But there are two other issues in your code.
In your first
if
statement you check if the argument is longer than 5, but return a message about it being too short, it should be the other way around. This also applies to yourelif
in reverse.You have misspelled string as sting within your first message.
If you fix those issues like this:
def just_right(argument):
if len(argument) > 5:
return "Your string is too long" # Changed "sting" to "string" and "short" to "long"
elif len(argument) < 5:
return "Your string is too short" # Changed "long" to "short"
else:
return True
Then your code will be accepted. You might also notice I removed the parenthesis around the strings, while they won't cause any errors with your code they are not actually needed. And it's not common to use parenthesis when returning things in Python.
Ali S
2,605 PointsThank you! I appreciate your help.