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!

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.

def just_right(characters):

    while len(characters) < 5:
        print("Your sting is too long")
            if len(characters) > 5:
                print("You sting is too short")
            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


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"
         return True

You also have some spelling errors in your strings I corrected