Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Number Game App String length

Didier Borel
Didier Borel
2,837 Points

string length

i can't see why this is not returning any answer at all. can someone help me out. thxs

strlen.py
def just_right(string):
    if len(string)<5:
        return("Yours string is too short")
    elif len(string)>5:
        return("Your string is too long")
    else:
        return(True)

2 Answers

andren
andren
28,520 Points

You just have a small typo. In your first string you have typed Yours instead of Your. Challenges are often very picky about strings so even a minor typo like that is enough for the challenge checker to mark your answer as wrong.

If you simply fix that typo then your code will work. Like this:

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

You might notice I also removed the parenthesis you used when returning the values. That is not strictly necessary as they won't cause any errors. But because return is not a function, but a keyword it is considered a bad practice to make it look like a function call by using parenthesis.

Didier Borel
Didier Borel
2,837 Points

ahh when i take off the () after return , it works, so that must be the correct answer

thxs

Antonio De Rose
Antonio De Rose
20,882 Points

nothing wrong with the logic, your approach is right, the way you have implemented the logic is also right spelling mistake, the questions are really picky even in the sentences between the quotes.

def just_right(string):
    if len(string)<5:
        return("Yours string is too short") #not Yours, but Your
    elif len(string)>5:
        return("Your string is too long")
    else:
        return(True)