Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Number Game App String length

Stefan Vaziri
Stefan Vaziri
17,453 Points

Unsure of how to do this...

I think I got the if statements right but I don't think I got the return True statement in the right place or format.

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

3 Answers

Adam Young
Adam Young
15,791 Points

In this challenge you're expected to return the string, not print() it. Tricky wording :)

Also, double-check the comparison operators in your if statements and you should be all set.

Stefan Vaziri
Stefan Vaziri
17,453 Points

So I updated it but I'm still getting the wrong answer:

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

I'm trying to figure out what I'm doing wrong with the comparison operators but not sure how to fix it.

Stefan Vaziri
Stefan Vaziri
17,453 Points

Nvm I figured it out!

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

Thanks for your help Adam!