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

Printing messages based on the length of a string

I'm being told this code isn't correct to complete this code challenge. However, I ran this code in pycharm and it worked just fine.

There have been a few times now where I was "stuck" on these code challenges over a minor detail. This time I have no idea why it's saying my code isn't correct and now I can't move on with the lesson...

There really need to be a "Check answer" or "Skip challenge" option.

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 long")
    else:
        return True

1 Answer

Nick Osborne
Nick Osborne
4,612 Points

Hi Shaun Yeah, deserves a pass! Simply should be return instead of print...

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

Oh wow... really? If the challenge had the word 'return' written within a code block then it would have been more obvious that I had to 'return' the string instead of printing it which made more sense at the time...

Regardless, thank you.