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

I need to creat a function that takes a single argument, a string if its length is more that five, I should write that

its length is too long, if it Is less that 5 I should write that its length is too short if its is 5 I should return True where is my mistake? thank you very much for the help

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

2 Answers

hi, there is nothing wrong with your code. The problem is that he has asked you to 'return' "Your string is too short" rather than print() it. Everything looks good otherwise.

def just_right(string):
    if len(string) < 5:
        return "Your string is too short"        # return here instead of print
    elif len(string) > 5:
        return "your string is too long"         # return here instead of print
        return True

Thank you very much. I managed to do it