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

Mint Milano
Mint Milano
3,114 Points

could not get the simple program right..where do you think i have made a mistake..?

did i miss something?

strlen.py
def just_right(str):
    if len(str)<=5:
        print ("Your string is too short")
    return True

2 Answers

Amir Eskandari
Amir Eskandari
9,153 Points

Hey there,

You are very close. Read the question very carefully and try something like this:

def just_right(str):
    if len(str) < 5:
        return something
    elif len(str) > 5:
        return something
    else:
        return something

Let me know if you have more questions.

Mint Milano
Mint Milano
3,114 Points

Thank you! yea sure! cool!

For this challenge, the Code challenge wants you to do more than one if/elif/else.

The challenge wants you to be able to return either "Your string is too short", "Your string is too long", or True, not only "Your string is too short".

Also, you should be printing anything, but returning the string (if the string is greater than or less than 5).

Lastly, I should point out that <= and >= mean "less than or greater to" and "greater than or equal to", so if the length is five, it would go inside that if which is wrong. Instead use > and <.

If you hook those other messages up, you should end up with:

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

Good luck! ~alex