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

I get Try again, the same piece of code worked in a separate python console

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

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

3 Answers

andren
andren
28,558 Points

The challenge asks you to return the strings, it does not ask you to print them. While those two things looks somewhat similar when you run the code in the REPL they do very different things, as you'll start to learn later on.

So if you replace the print calls with return statements like this:

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

Then your code will be accepted.

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi there,

Yes, your code will work in the Python Console, because it is correct syntactically :thumbsup:. However, it is not exactly what the challenge asks for. Challenges are very specific with the instructions and it needs to be followed explicitly. Here the instructions say to "return" the strings, but you are printing them.
Just fix that up and you're good to go! :)

Keep Coding! :dizzy:

Thanks, guys! That was my bad.