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

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