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

aditya yadav
aditya yadav
1,505 Points

Where I am doing it wrong

Pls help me with the code

strlen.py
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

In python you must regard indentation. Also you must write return instead of print

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


just_right('your string')
aditya yadav
aditya yadav
1,505 Points

Thank you for the answer , I know it is correct , but the code challenge is still giving error

andren
andren
28,558 Points

In addition to the indentation error that sepehr akbarzadeh pointed out you have another issue in your code. Namely that you are printing out the strings, not returning them, which is what the task's instruction asks you to do.

If you change print to return like this:

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

Then your code will work.

yeah, you are right

Thank you

pardon me for my bad answer.

andren
andren
28,558 Points

Don't worry, your answer is not bad as you had no way of knowing about that issue unless you went and read the challenge's instructions :smile:. I have just answered a bunch of question about this challenge in the past so I'm quite familiar with what the challenge requires.

Though it is often a good idea to verify that the solution you post passes the challenge before you post it as an answer, that's my personal policy, and it has stopped me from posting incomplete answers quite a number of times.

When a post is associated with a challenge you can go to the challenge just by clicking on the "View Challenge" button that is found near the top of the page. So it's pretty easy to verify your solution and to check on the instructions of the task.

Thank you for your complete answer, i'm novice in TeamTreeHouse community.

i got the point.