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

Raelin Jaqueth
Raelin Jaqueth
1,586 Points

Can someone please look over my code to see what I am doing wrong?

Here is my code for the String length exercise. I have tried multiple variations, but I can not get the code to work. someone please help!

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

strlen.py

2 Answers

Matthew Francis
Matthew Francis
6,967 Points
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 Jones
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Jones
Java Web Development Techdegree Graduate 23,933 Points

Not to be nit picky, but to make the code a little cleaner, the parentheses around return can be removed in the if and elif statements.

Matthew Francis
Matthew Francis
6,967 Points

I just find it easier to read haha, maybe it's because Im used to Java/Javascirpt

Idan Melamed
Idan Melamed
16,285 Points

You can also write it without the 'elif' and 'else':

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