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 trialHussein Amr
2,461 PointsWhat am I doing wrong?
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")
else:
True
just_right("string")
3 Answers
johngross
5,439 PointsYou don't need " " around the variable names, your else never returns true and replace all the print() with return.
def just_right(string):
if len(string) < 5 :
return("Your string is too short")
elif len(string) > 5 :
return("Your string is too long")
else:
return True
Steven Ang
41,751 PointsLike johngross wrote, you don't need quotation marks around the arguments/variables or else it would be invalid and give you a syntax error. The challenge wants you to return the value, not print them out. Inside the else block, you need to return the boolean value or else you will get a syntax error. Just fix all of that, you will pass the challenge.
def just_right(str):
if len(str) < 5:
return "Your string is too short"
elif len(str) > 5:
return "Your string is too long"
else:
return True
Hussein Amr
2,461 PointsThanks guys appreciate it
Steven Ang
41,751 PointsSteven Ang
41,751 PointsActually, you don't really the parathesis in the return method. You can just simply do it:
return "Your statement"