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

Alejandro Byrne
Alejandro Byrne
2,562 Points

Why does my code not work?

I'm supposed to make a function called "just_right" that returns "Your string is too long!" or "Your string is too short!" depending on wether the string is more or less than 5 characters long. If it is 5 - or, else - then just return True

strlen.py
def just_right(asd):
    if len(asd) < 5:
        return("Your string is too short")
    elif len(asd) < 5:
        return("Your string is too long")
    else:
        return(True)
joshthorn
joshthorn
30,751 Points

In your elif, you say to return if the string is less than 5. The symbol < means less than, for more than use >.

So, for your elif, the code would be:

elif len(asd) > 5:
        return("Your string is too long")

1 Answer

Steven Parker
Steven Parker
231,269 Points

You may just have a typo.

On line 4, did you mean to write this:

    elif len(asd) < 5:

I'm guessing that you actually meant to write this instead:

    elif len(asd) > 5:
Alejandro Byrne
Alejandro Byrne
2,562 Points

Oh wow, that was so dumb of me! Thanks anyway, it worked!