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

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
21,205 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
21,205 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!