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

Philip Kalinda
Philip Kalinda
4,663 Points

just_right

struggles :( 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.

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

4 Answers

Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,132 Points

The function must "return", not "print".

#argument = str()   #this is not necessary for the challenge
def just_right(argument):
    if len(argument) > 5:
        return("Your string is too long")
    elif len(argument) < 5:
        return("Your string is too short")
    else:
        return True
Chris Freeman
Chris Freeman
Treehouse Moderator 68,426 Points

Also: Parens are not necessary in the return statement.

Philip Kalinda
Philip Kalinda
4,663 Points

Thanks a bunch guys! really appreciate the help! Martin Cornejo Saavedra & Chris Freeman

damn. u were right. thats what was holing me up. i had print instead of return

Completed the challenged and was surprised how simple it was actually.....

i managed to do the challenge but cant quite get why the function must return or why you cant use the prints.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,426 Points

The challenges are graded by a checker program that only can "see" results from a program's perspective. That is, it only sees what is returned by the function. So the checker calls the function and then evaluates the returned object for correctness.

The output of a print statement would show up on a console for human consumption but would not be seen by the checker.

ah okay that makes sense. Thanks