Python Forum

Full Version: NameError: name '' is not defined
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm new to python. I've coded this to check whether an inputted name is between 3 and 10 letters and to ask the user whether they want to change it or not if it is. However, when I try to run it I get the error: 

File "/Users/archie/Downloads/namecheck/namecheck.py", line 11, in <module>
name = input("What's your name? ")
File "<string>", line 1, in <module>

NameError: name 'test' is not defined

There's probably an easy solution for this, but I am really confused as I can't see anything visibly wrong with the code. Can anybody help me? I am running the code in Wingide Pro v6.1.2-1.

namework = 0
while namework == 0:
    name = input("What's your name? ")
    if len(name) > 10:
        ncwork = 0
        while ncwork == 0:
            ncheck = input("Are you sure " + name + " is your name? Most names have between 3 and 10 characters. YES or NO ")
            ncheck = ncheck.lower()
            if ncheck == "yes":
                ncwork = 1
                namework = 1
            elif ncheck == "no":
                ncwork=1
    elif len(name) < 3:
        ncwork = 0
        while ncwork == 0:
            ncheck = input("Are you sure " + name + " is your name? Most names have between 3 and 10 characters. YES or NO ")
            ncheck = ncheck.lower()
            if ncheck == "yes":
                ncwork=1
                namework=1
            elif ncheck == "no":
                ncwork=1
    else:
        namework=1
This looks like you are running Python 2.7 or earlier, the code you have is written for Python 3.0 or later. The behavior of the input function changed in Python 3.0.

You want to learn on 3.0 or later, but you need to make sure you are running your code in the appropriate version.