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

Coding Challenge - creating a function and testing length of string

Trying to figure out why this doesn't seem to work. I just get "Bummer! Try again" which is less than helpful. I'm not entirely sure where or if an error exists. Using this exact code in my own IDE seems to work fine. If I seed the string value before running, I get the correct response when this code is ran independently. Not sure what's wrong here.

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

Something is wrong here... this isn't the code I submitted. I copy and pasted from my IDE which has the correct version. Something is making my code present incorrectly, I believe. Here's the real code: def just_right(guess): if len(guess) < 5: print("Your string is too short") elif len(guess) > 5: print("Your string is too long") else: return True

1 Answer

Deleted my previous answer because I realized there was more to it. You also need to return the strings, instead of printing as that is what the challenge is expecting. Hope this helps!

Thanks. But the first part helped a bunch, too. Didn't see it.

Glad to help!