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

Where's my error?

This task seems so simple and yet I don't see where I'm going wrong. I've had no issues up to this point. Where is my mistake?

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

3 Answers

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey,

you just have to return your strings instead of printing them out. :)

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

Good spot! I thought it was the last else, which is unnecessary; I hadn't spotted the print, rather than return!

Steve.

Tobias Helmrich
Tobias Helmrich
31,603 Points

Thanks, Steve! But you're also right, the last else is indeed unnecessary, so good spot as well! :)

Team effort! :smile:

Tobias Helmrich
Tobias Helmrich
31,603 Points

Yes! Like always four eyes see more than two! :)

Hi Tim,

You don't need the last else:

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

I hope that helps,

Steve.

Thanks guys. I guess I need to read the task better. I knew it had to be something simple.