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

Identation error

I'm a bit stuck with this exercise. It keeps giving me several errors depending on what I try. I feel the below is the closest I could come to a workable solution. If anybody could help it would be much appreciated.

def just_right():
name = 'kevin'
  if len(name) < 5:
    print("Your string is too short.")
  else:
    print("Your string is too long.")
strlen.py
def just_right():
name = 'kevin'
  if len(name) < 5:
    print("Your string is too short.")
  else:
    print("Your string is too long.")

I've also tried this with the input method and have name as follows:

name = input("What's your name?")

This does not alter anything to the problem unfortunately.

2 Answers

I'm more confused now honestly.. :D

Kourosh Raeen
Kourosh Raeen
23,732 Points

Delete the line name = 'Kevin' since it is not needed anyway. Then change the function's definition from:

def just_right():

to:

def just_right(arg):

Now, use an if-elif-else statement to check the length of arg and return an appropriate response.

Kourosh Raeen
Kourosh Raeen
23,732 Points

The line:

name = 'kevin'

needs to be indented. Also, your function needs to take a string argument and instead of printing it should return those strings in the if-else statement. You also need an elif and return True in the else part.