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

Robert Gettings
Robert Gettings
1,902 Points

What is the problem here? I even tried it out in Workspace and it's fully functional. Can anybody help? (String length)

I just get the message "Try Again"

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

1 Answer

andren
andren
28,558 Points

They ask you to return the strings. You are printing them, which is not the same thing.

If you return the values like this:

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

Then your code will work fine.

Robert Gettings
Robert Gettings
1,902 Points

Oh, you're right. I just saw the "Your string is too short" and thought, that it should be printed, Thank you.

andren
andren
28,558 Points

Yeah to be honest it's not really that common to return strings with messages in them like this, unless you have another method printing out what this method returns. Printing them out directly would have made more sense. But the point of the exercise is likely just to see if you know how the return keyword works.