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

Joshua Faulk
Joshua Faulk
5,894 Points

String Length Challenge Failing

Hey, so when I put my code into the python workspace, the results come out exactly as they should, but it says I'm still failing the challenge, so I'm not really sure where the issue is.

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

3 Answers

Like what Yevhen said, you don't print in the "if" "elif" clause. Instead you should replace the print function to the return keyword. The code:

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

Hope it helps! ~xela888

Yevhen Kim
Yevhen Kim
6,134 Points

you need to return not print and () are not required

Hey Yevhen, you are wrong here. You have to use () in Python 3. If you are talking about Python 2, then you are right after all.

Luis Rodriguez
PLUS
Luis Rodriguez
Courses Plus Student 509 Points

not sure if any one has noticed this issue but i noticed that the tab button only moves 2 spaces over and I usually indent it 4 spaces but the code doesnt seem to go thru with an indentation of 4 spaces . Spent so much time trying to figure out why my code wasnt going thru on many of the code challenges , hope this helps someone