Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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