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

Povilas Jurgaitis
Povilas Jurgaitis
6,792 Points

Can't pass string length objective

Please help me what I do wrong. My code:

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

strlen.py
def just_right(str):
  if len(str) < 5:
    print('Your string is too short')
  elif len(str) > 5:
    print('Your string is too long')
  else:
    return True
Nathan Tallack
Nathan Tallack
22,160 Points

Woah. That's trippy. Your code looks good to me. Will be interesting to see what was wrong.

So, yeah, how many have been stuck in this technicality? I know I spent 15 minutes til I reached this "forum".

1 Answer

Stephen Gheysens
Stephen Gheysens
11,935 Points

Hi Povilas! This is pretty subtle, but it looks like the challenge is asking for you to return the strings "Your string is too short" or "Your string is too long", rather than just printing them. In your case, the only time there is a return value from this function is when the string is exactly 5 characters long.

Povilas Jurgaitis
Povilas Jurgaitis
6,792 Points

Thank you very much. I returned a string with text and it was it.