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

jmac pd
jmac pd
11,490 Points

String Length: Am I missing something?

not sure what I am missing here. """ Create a new function named just_right that takes a single argument, a string. If the length of the string is less than five characters, return "Your string is too short". If the string is longer than five characters, return "Your string is too long". Otherwise, just return True. """

Maybe I am reading the question wrong?

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

2 Answers

Timm Derrickson
Timm Derrickson
20,978 Points

Your logic is fine, just re-read the question. You need to return the answer, not print it. So, on each of your conditionals, instead of printing the answer on the first two, return them.

I hope that helps.

jmac pd
jmac pd
11,490 Points

that's it! I make that mistake too often to not have caught it.

I'm over here running my code in the shell scratching my head for 2 days.

thank you.

Timm Derrickson
Timm Derrickson
20,978 Points

No problem. I have done it several times. I ran your code and started scratching my own head wondering why it was not counting it as correct. So you are not the only one!