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

victor E
victor E
19,146 Points

my code isn't working!!

not sure what I am missing here.

strlen.py
def just_right():
    while True:
        input(" ")
        if len(input) < 5:
            print("Your string is too short")
        elif len(input) > 5:
            print("Your string is too long")
        else:
            return True

1 Answer

AJ Salmon
AJ Salmon
5,675 Points

Hey Victor, you won't need input for this. When you write a function, you set the parameters. Your function takes 0 arguments, and this function needs to take 1, a string. An argument is passed to a function when that function is called, and you need to tell it how many arguments to expect. So, when setting the parameters, tell it that it will take a single argument (a string, but you don't need to specify that, just that there will be one of them). You can name this argument whatever you want, but try to stay away from one-letter names or names that are already designated keywords (like str, list, or int). Here's what the starting lines should look like:

def just_right(random_string):
    if len(random_string) > 5:

Now, like I said, you can name that parameter something else, if you want. It's just a placeholder for the actual string that will be passed when the function is called later on by the code challenge, or anyone else that calls it! Hope this helps, and happy coding!

victor E
victor E
19,146 Points

Thank you for your help!

AJ Salmon
AJ Salmon
5,675 Points

My pleasure :)