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

is this code not right?

i put this code into the workspace and it works, but when i use it in the website it don't work. what im i doing wrong?

strlen.py
def just_right(x):
    while len (x) < 5:
        print("your string is too short")
    if len (x) > 5:
        print("your string is too long")
    else:
        return True
just_right("games")

1 Answer

Gianmarco Mazzoran
Gianmarco Mazzoran
22,076 Points

Hi,

You got an error because you print() the messages instead of return.

def just_right(x):
    while len(x) < 5: # pay attention for the space between the function and the parenthesis
        return "your string is too short"
    if len(x) > 5: # pay attention for the space between the function and the parenthesis
        return "your string is too long"
    else:
        return True
just_right("games") # you don't need to call the function

yh it works, thanks.

the reason i printed instead of returning is because there was another activity like this and it wasn't allowing to return, but it worked when i used print.

i must have misread it.

thanks!!!!!