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 trialSky Lu
1,260 Pointsdef function problems:
I've tested my codes, it works perfect, but I can't pass the task
the taks is: Create a new function named just_right that takes a single argument, a string. If the length of the string is less than five characters, return "Your string is too short". If the string is longer than five characters, return "Your string is too long". Otherwise, just return True.
def just_right(one_string):
if len(one_string) < 5:
print("Your string is too short")
elif len(one_string) > 5:
print("Your string is too long")
else:
return True
5 Answers
markmneimneh
14,132 PointsThe challenge is not asking you to print the string ... it asking you to return the string.
pay attention to this:
print("Your string is too short")
it needs to be a return statement
Alexander Davison
65,469 PointsI think this post explains how print
and return
are different. I understand it is in Swift, but still, just ignore the code, read the answers :)
Simple answer to this question:
Print displays a value onto the screen.
Return actually returns a value that can be later processed. Keep in mind that return doesn't print anything (unless you
I hope this helps. ~Alex
Alexander Davison
65,469 PointsBy the way, does anybody want to try out my challenge? :)
markmneimneh
14,132 PointsHi
this may help
def just_right(one_string):
if len(one_string) < 5:
return("Your string is too short")
elif len(one_string) > 5:
return("Your string is too long")
else:
return True
#
#
my_return = just_right("hell")
print(my_return)
#
#If this was a banking app ... and I return am account balance, then
#I can use this return account balance to approve a purchase for example
Sky Lu
1,260 PointsIt's just like, when you are going to create an account on a website, they request an ID, if you only type hell, the web will show you, sorry, your ID is too short, right? something like that?
markmneimneh
14,132 Pointsright ... the value is returned and then it get sent to another function to check if this id valid (example ... look up in a database) ... if found and the password is ok ... then you are in ... otherwise, you get a declined.
Sky Lu
1,260 PointsThank you for your patient, thanks a lot.
Sky Lu
1,260 PointsSky Lu
1,260 PointsOh, no....am so careless, thank you mark.
BTW: what's the purpose for return, return can't get anything back on the screen.