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 trialRaelin Jaqueth
1,586 PointsCan someone please look over my code to see what I am doing wrong?
Here is my code for the String length exercise. I have tried multiple variations, but I can not get the code to work. someone please help!
def just_right("single"): if len(just_right) < 5: return "Your sting is too short" elif: len(just_right) > 5: return "Your sting is too long" else: return True
2 Answers
Matthew Francis
6,967 Pointsdef just_right(argument):
if len(argument) > 5:
return("Your string is too long")
elif len(argument) < 5:
return("Your string is too short")
else:
return True
Idan Melamed
16,285 PointsYou can also write it without the 'elif' and 'else':
def just_right(arg):
if len(arg) < 5:
return "Your string is too short"
if len(arg) > 5:
return "Your string is too long"
return True
Chris Jones
Java Web Development Techdegree Graduate 23,933 PointsChris Jones
Java Web Development Techdegree Graduate 23,933 PointsNot to be nit picky, but to make the code a little cleaner, the parentheses around
return
can be removed in theif
andelif
statements.Matthew Francis
6,967 PointsMatthew Francis
6,967 PointsI just find it easier to read haha, maybe it's because Im used to Java/Javascirpt