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 trialmarvelousstudent317
Python Web Development Techdegree Student 1,237 Pointswhat have I done wrong????
what have I done wrong here????
def just_right(string):
string = str(input(" "))
if len(string) > 5:
print("Your string is too long")
return True
else:
print("Your string is too short")
3 Answers
Alexander Davison
65,469 PointsA few things:
- Why are you setting the parameter
string
to the user input? The challenge didn't ask you to do that. - You are printing "Your string is too long" and returning True when the string length is greater than five (why are you returning True? You should return True if the number is perfect).
- You are printing "Your string is too long" and "Your string is too short" when you are supposed to return the strings.
If you fix those, you should have the correct code:
def just_right(string):
if len(string) > 5:
return "Your string is too long"
elif len(string) < 5:
return "Your string is too short"
else:
return True
Good luck!
~Alex
john larson
16,594 PointsYes to what Alex said. Sometimes I like to lay it out like this:
def just_right(string): # <-- Create a new function named just_right that takes a single argument, a string.
if len(string) < 5: # <-- If the length of the string is less than five characters,
return "Your string is too short" # <-- return "Your string is too short"
elif len(string) >5: # <--If the string is longer than five characters,
return "Your string is too long" # <-- return "Your string is too long"
else: # <-- Otherwise,
return True # <-- just return True.
So I can keep track of what I'm doing.
marvelousstudent317
Python Web Development Techdegree Student 1,237 Pointsthank you
Alexander Davison
65,469 PointsNo problem :)