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

string length exercise

I can't figure it out! I used the same structure used in the odd_even number exercise but it doesn't work. My code is the following: arg1 = str()

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

just_right(arg1)

strlen.py
arg1 = str()

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

just_right(arg1)

1 Answer

Michael Hulet
Michael Hulet
47,913 Points

Pay attention to what the challenge asks you to do here. You'll never need to print anything. Instead, you should return in all cases. Also, in the case that the length is 5, you should return the boolean True instead of the string "True". You don't need to call the function at the end, either. Once you make those changes, your code passes the challenge. Great job!