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 trialTim Powell
1,803 PointsWhere's my error?
This task seems so simple and yet I don't see where I'm going wrong. I've had no issues up to this point. Where is my mistake?
def just_right(trees):
if len(trees) < 5:
print("Your string is too short")
elif len(trees) > 5:
print("Your string is too long")
else:
return True
3 Answers
Tobias Helmrich
31,603 PointsHey,
you just have to return your strings instead of printing them out. :)
def just_right(trees):
if len(trees) < 5:
return "Your string is too short"
elif len(trees) > 5:
return "Your string is too long"
else:
return True
Steve Hunter
57,712 PointsHi Tim,
You don't need the last else
:
def just_right(string):
if len(string) > 5:
return "Your string is too long"
elif len(string) < 5:
return "Your string is too short"
return True
I hope that helps,
Steve.
Tim Powell
1,803 PointsThanks guys. I guess I need to read the task better. I knew it had to be something simple.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsGood spot! I thought it was the last
else
, which is unnecessary; I hadn't spotted the print, rather than return!Steve.
Tobias Helmrich
31,603 PointsTobias Helmrich
31,603 PointsThanks, Steve! But you're also right, the last
else
is indeed unnecessary, so good spot as well! :)Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsTeam effort!
Tobias Helmrich
31,603 PointsTobias Helmrich
31,603 PointsYes! Like always four eyes see more than two! :)