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

Bummer! Try again.. Am I misinterpreting the instruction?

Got an error... Am I misinterpreting the instruction? Or this problem is caused to use 2 spaces indentation rather then 4 spaces? I don't have any clue why I got this error.

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

1 Answer

You will need to use 'return' instead of 'print' for the two if statements. It just wants you to return the string instead of printing it to the console. This should work:

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

Thanks for the reply! Now pass the challenge finally! By the way, I think the code posted below miss two operations and a number.

For some reason it isn't showing the operators or number when I specify python using ~~~ to post my code. I just indented it instead to recognize the code so they are appearing now. If you feel like this satisfies your question, I would love for the upvote (up arrow next to answer) or best answer recognition. Happy coding!