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 trial

Python Python Basics (2015) Number Game App String length

Hussein Amr
Hussein Amr
2,461 Points

What am I doing wrong?

What am I doing wrong?

strlen.py
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

You 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
Steven Ang
41,751 Points

Actually, you don't really the parathesis in the return method. You can just simply do it:

return "Your statement"
Steven Ang
Steven Ang
41,751 Points

Like 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
Hussein Amr
2,461 Points

Thanks guys appreciate it