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

Create a new function names just_right that takes a single argument, a string. PYTHON help please

this is my code can someone tell me what I am doing wrong, I have run it in my terminal and everything is working as it should but for some reason I can not pass this challenge.

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

[MOD: added ```python markdown formatting -cf]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Your code is very close. You need to use return instead of print for the strings.

Thank you Chris!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

print is used to display text on a console or STDOUT. This output text is not accessible by other code.

return is a built-in command that returns an object pointer to the calling code.

The challenge checker calls the function and inspects the returned object for correctness.

If a function does not have an explicit return statement then an implicit default is used:

    return None

So without the return the checker sees None