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

huyen nguyen
huyen nguyen
850 Points

what's wrong with my code?

please help me with the code: def just_right(a): if len(a)<5: print ("your string is too short") return elif len(a)>5: print("Your string is too long") return else: return True

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

3 Answers

Junjie Huang
Junjie Huang
4,704 Points

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".

andren
andren
28,558 Points

The return keyword goes before the value you want to return, it does not go on a line by itself with nothing following it. So to return the string "your string is too short" for example you would write:

return "your string is too short"

Since this task does not require you to print anything you can solved this task by simply removing your print statements and moving the strings down to the same line as the return statement is currently.

Joseph Marcus
Joseph Marcus
11,069 Points

Hi huyen nguyen, like everyone else has said.

The problem is your return statement. The return statement always needs to return something.

So rather than print("your string is too short"), type return "your string is too short" instead.