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

just_right challenge

tried in my own environment, it all works out, but can't pass it in your worksspace, can you check ? thanks so much

def just_right(item): if len(item) < 5: print("{} is too short".format(item)) elif len(item) > 5: print("{} is too long".format(item)) else: Return True

strlen.py
def just_right(item):
    if len(item) < 5:
        print("{} is too short".format(item))
    elif len(item) > 5:
        print("{} is too long".format(item))
    else:
        Return True
Jeff Muday
Jeff Muday
Treehouse Moderator 28,722 Points

The capital "R" of "Return" is what is causing the issue. It should be lower case "return" instead.

9 Answers

Ryan S
Ryan S
27,276 Points

Hi Coffee,

Your logic is correct, but there are 3 issues with your code that are causing it to not pass.

First, the challenge does not ask you to print anything. It asks you to return the strings.

Second, the return keyword should be lowercase.

And lastly, your strings are not what the challenge asked for. You'll find that these challenges are very picky, especially when it comes to strings. Even adding a capital letter or a punctuation mark where one shouldn't be will be enough to cause the code to fail.

The strings you will need to return are: "Your string is too short" and "Your string is too long". If you change the output to anything other than those exact strings then the code will not pass.

Hope this helps.

Got it , thanks

however it still doesn't work:

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

Ryan S
Ryan S
27,276 Points

Hi Coffee,

If you look closely at your strings, you have an extra space at the very beginning of both of them. This extra space is enough to make the string different than what the challenge is expecting.

" Your string is too short"

# versus

"Your string is too short"

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

'''

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

Ryan S
Ryan S
27,276 Points

To format your code, use 3 backticks, not apostrophes. The backtick is found in the upper left corner of your keyboard, sharing the same key as the ~ symbol.

It always tell me: " Bummer! just_right didn't return the right answer. Restart "

def just_right(item):
    if len(item) < 5:
        return "Your string is too short"
    elif len(item) > 5:
        return "Your strin is too long"
    else:
        return True
Ryan S
Ryan S
27,276 Points

One more small typo :)

You forgot the 'g' in "string" in your second return statement. Fix that and it should pass.

Also, just a tip, you can leave comments below answers by clicking the "Add Comment" button, rather than adding a new answer each time. It helps keep the discussions a little more organized.

Answers can be upvoted and downvoted which can change their order. Leaving comments ensures that posts can remain in a logical order if they are related to a specific answer.

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

Sorry for repeating , Oops

I got it solved , just one more space in the string cause to code to fail