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

just_right function seems fine to me but it is marked wrong. If anyone can see what is wrong I would appreciate it.

Feedback just says 'Bummer! Try again'

Thank you both for that help. I have replaced all prints with returns and it is correct. John

3 Answers

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Try this code:

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

Also notice, for markdown code, use backticks

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Based on your code, you need to use return instead of print

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

Hi Chris, sorry to waste your time. I had to retype the code again to paste it in and in my haste typed return instead of print! My original code was

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

This also gets marked 'Bummer'

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Please, post code with your function here. We can't see your code in a challenge.

Thanks for the prompt reply. I ticked a box which, I think' said include code with post but anyway my code is

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

I'd appreciate any help you can offer.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Sergey, Thanks for your help in the forum. I would like to suggest that it's better to ask for clarification and code posts as a comment to the original post instead of as an Answer. That way others can see if the question still needs attention.

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Ok, thank you Chris for your suggestion. I will do this next time ;)