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

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,733 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,733 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.