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

I really don't know how to do this without using input

So I have done this and I have an input function in it.

Can someone show me how to make this without using input because it is not allowed to use that command in challenges.

P.S I have done the same in python IDLE and it worked perfectly

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

1 Answer

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Marko,

The challenge wants you to define the function with an input parameter named string. That would look like this.

def just_right(string):

Since it's passed to the function, you don't need to call input. The challenge also wants you to consider the case where the string has 5 characters. For this, you can extend the if condition to include an elif statement for the length being greater than 5, and follow that with an else that returns true.

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

I hope this helps.