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

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,558 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,884 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)