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 trialJoshua Stokes
769 PointsChallenge Task - String Length (Answer not accepted in treehouse)
I'm having trouble completing this challenge task on string length. The code attached definitely works in a python interpreter, however treehouse doesn't like it. What am I doing wrong?
def just_right(string):
if len(string) < 5:
print("Your string is too short")
elif len(string) > 5:
print("Your string is too long")
return True
1 Answer
Alexander Davison
65,469 PointsFor the first two messages ("you string is too long" and "your string is too short"), you only printed the messages so really if the function is called with the argument 6, this is was it'll happen:
- It will print out "You string is too short!"
- It will return True
So, to fix that, replace both print*s with a *return. :)
Good luck! ~alex
Joshua Stokes
769 PointsJoshua Stokes
769 PointsOk that works, but do you mean argument 6 as a string, so it looks like this... just_right("6") or something else.
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsNo, I meant 6 as a number :)
I can't say "is this text greater than this number?" because it just doesn't make sense and strings are text :)
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsWhat's confusing is that you said the "argument 6" but the function is expecting a string to be passed in.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsI think that's what Joshua was trying to get clarification on.
Joshua Stokes
769 PointsJoshua Stokes
769 PointsOk, I think I'm starting to understand you now, but just incase.
When you talk about argument 6, do you mean that instead of determining whether a string is equal to 5 characters, to determine whether a string is equal to 6 characters?
Update - Yes, what Jason said