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

kevin cleary
kevin cleary
4,690 Points

I tried my code in the python shell, and it does what the instructions call for. But, the challenge says it is wrong.

What is wrong with My Code:

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

1 Answer

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hola,

Well, your code looks to be right because it's printing the answer to the console. It's not asking you to print the answer it's asking you to return the answer. This means some function called this function and it's returning to it what it needs. It's not printing anything at this point in time. So in the console yes, yours appears to be right, but it's not actually right for which in the context the question is asking.

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

This code returns the string requested based on the value being passed in depending on if it's more or less than 5. Otherwise it just returns true.

Does that make sense? If not please let me know your questions or I can try to be more clear.

kevin cleary
kevin cleary
4,690 Points

Wonderful. I feel silly for not catching that. Thank you.

Ryan Ruscett
Ryan Ruscett
23,309 Points

Right on! It happens to us all no matter how good we get. Glade to help when I can!