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

Syntax check for just_right function

Not sure what might be wrong with the syntax, other than having a colon out of place or maybe alms is out of place.

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

1 Answer

andren
andren
28,558 Points

There are no syntax errors, you are just returning the wrong string. You are returning "Your string is too short" both when the string is too short and too long.

If you return the right string like this:

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

Then your code will work.

You might notice that I also changed the formatting of your return statements a bit by removing the parenthesis and adding a space. This is not technically required but it is how return statements are typically written, and keeping your code consistent with common formatting practices is a good habit to develop since it will make the code easier to read by other developers.