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 trialSri Swaminathan Vanarasi
621 PointsI get Try again, the same piece of code worked in a separate python console
def just_right(word): if len(word) < 5: print ("Your string is too short") elif len(word) > 5: print ("Your string is too long") else: return True
def just_right(word):
if len(word) < 5:
print ("Your string is too short")
elif len(word) > 5:
print ("Your string is too long")
else:
return True
3 Answers
andren
28,558 PointsThe challenge asks you to return the strings, it does not ask you to print them. While those two things looks somewhat similar when you run the code in the REPL they do very different things, as you'll start to learn later on.
So if you replace the print
calls with return
statements like this:
def just_right(word):
if len(word) < 5:
return "Your string is too short"
elif len(word) > 5:
return "Your string is too long"
else:
return True
Then your code will be accepted.
Jason Anders
Treehouse Moderator 145,860 PointsHi there,
Yes, your code will work in the Python Console, because it is correct syntactically . However, it is not exactly what the challenge asks for. Challenges are very specific with the instructions and it needs to be followed explicitly. Here the instructions say to "return" the strings, but you are printing them.
Just fix that up and you're good to go! :)
Keep Coding!
Sri Swaminathan Vanarasi
621 PointsThanks, guys! That was my bad.