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

How do you get this to work?

It won't let me pass and I don't know what I have to add.

strlen.py
def just_right(characters):

    while len(characters) < 5:
        print("Your sting is too long")
        else:
            if len(characters) > 5:
                print("You sting is too short")
        else:
            if len(characters) = 5:
                return True

2 Answers

You're on the right track but need to make some changes.

You don't need a while loop so start by removing that and replacing it with an if statement.

Then instead of doing

else:
    if 

Use the elif

elif #conditional statement

Then after your if statement and elif statement, end with and else statement that returns True

You also need to return strings, no need to print anything in this challenge. So under each if, elif, and else should be a return that returns a plain string or True at the very end.

please explain more about the returns a plain string or True at the very end.

For example:

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

You also have some spelling errors in your strings I corrected