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

tangtai chen
tangtai chen
4,844 Points

how take a single argument?

here is my code, i works in python but not here, im not sure what it ask for me to do here, since it does not work with the INPUT, and when i delete the input it tells me string is not defined, can someone help?

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

just_right()

2 Answers

First off the calling the string function on input is redundant. The only data type an input will naturally be is a string.

#run this in a python terminal
name = input()
type(name)
age = input()
type(age)

Both the outputs of type will be < class 'str' >

irregardless the challenge is not looking for you to ask for input, it simply is having an argument passed to the function.

def just_right(arg):
    if len(arg) < 5:
        return "Your string is too short"
    elif len(arg) > 5:
        return "Your string is too long"
    return True

I totally understand now that you provided the answer, but the issue I have is the video never taught us how to use "arg" as an argument. I would have been stuck on this forever. None the less I have learned something new, thank you!