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 trialPaul Heneghan
14,380 PointsI've tried multiple variations on this with print or return, with and without parentheses.
def just_right(myStr): if myStr.length < 5: return "Your string is too short" elif myStr.length > 5: return "Your string is too long" elif myStr.length == 5: return True
def just_right(myStr):
if myStr.length < 5:
return "Your string is too short"
elif myStr.length > 5:
return "Your string is too long"
elif myStr.length == 5:
return True
3 Answers
Kevin Li
2,634 PointsIt's supposed to be len(myStr), not myStr.length.
Paul Heneghan
14,380 PointsD'oh! My apologies for the javascript "bleedover", that makes perfect sense, and --- it works! Thanks Kevin, and thank you Gavin for the fine tuning addition.
Marcin Tokarzewski
3,487 PointsI tried this code and i am getting "Bommer" why?
def just_right(svar): if len(svar) < 5: print("Your string is too short") elif len(svar) > 5: print("Your string is too long") else: return True
UPDATE: it should be "returned" not printed, therefore correct code is:
def just_right(svar): if len(svar) < 5: return "Your string is too short" elif len(svar) > 5: return"Your string is too long" else: return True
Gavin Ralston
28,770 PointsGavin Ralston
28,770 Pointslen() is a function you can use on collections, not a method you call from collections. Kevin's got it right.