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

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!