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 trialkevin cleary
4,690 PointsI tried my code in the python shell, and it does what the instructions call for. But, the challenge says it is wrong.
What is wrong with My Code:
'''def just_right(string): if len(string) < 5: print("Your string is too short") elif len(string) > 5: print("Your string is too long") else: return True '''
1 Answer
Ryan Ruscett
23,309 PointsHola,
Well, your code looks to be right because it's printing the answer to the console. It's not asking you to print the answer it's asking you to return the answer. This means some function called this function and it's returning to it what it needs. It's not printing anything at this point in time. So in the console yes, yours appears to be right, but it's not actually right for which in the context the question is asking.
def just_right(arg1):
if len(arg1) < 5:
return "Your string is to short"
elif len(arg1) > 5:
return "Your string is to long"
else:
return True
This code returns the string requested based on the value being passed in depending on if it's more or less than 5. Otherwise it just returns true.
Does that make sense? If not please let me know your questions or I can try to be more clear.
kevin cleary
4,690 Pointskevin cleary
4,690 PointsWonderful. I feel silly for not catching that. Thank you.
Ryan Ruscett
23,309 PointsRyan Ruscett
23,309 PointsRight on! It happens to us all no matter how good we get. Glade to help when I can!