Python - simple list function giving name error
<p>Fairly simple question, I imagine...I have literally just installed Python and am testing some of the beginner tutorials.</p>

<p>I wanted to create a menu that allows you to add items to a list, then check to see if theyre added: testing functions, and lists in the process.</p>

<pre><code>#create empty list and define variables
firstlist = {'joe'}
additem = "test"
printthis = "test"

#create menu, add or check name
def menu():
    #print what options you have
    print "Add to list: type '1'"
    print "Check for name: type '2'"
    print "To exit program: type '3'"
    return input ("Choose your option: ")

def addmenu():
    additem = input("Name of list item: ")
    firstlist.append(additem)
    print additem, "has been appended"

def checkmenu():
    printthis = input ("What are you looking for?: ")
    if firstlist.has_key(printthis):
        print "is in the list"
    else:
        print "is not in the list"

# Perform action
loop = 1
choice = 0
while loop == 1:
    choice = menu()
    if choice == 1:
        addmenu()
    elif choice == 2:
        checkmenu()
    elif choice == 3:
        loop = 0
    elif choice &gt; 3:
        print "You made an incorrect selection"
</code></pre>

<p>Heres my error:</p>

<pre><code>Traceback (most recent call last):
  File "C:\Python27\testing python\tutorials\dictionaryselection", line 32, in &lt;module&gt;
    addmenu()
  File "C:\Python27\testing python\tutorials\dictionaryselection", line 15, in addmenu
    additem = input("Name of list item: ")
  File "&lt;string&gt;", line 1, in &lt;module&gt;
NameError: name 'TESTING' is not defined
</code></pre>

<p>Not sure whats going on...Any help would be appreciated.</p>

<p>Working code below: converted to python 3.x</p>

<pre><code>#create empty list and define variables
firstlist = ['Joe']
additem = "test"
printthis = "test"

#create menu, add or check name
def menu():
    #print what options you have
    print ("")
    print ("Add to list: type '1'")
    print ("Check for name: type '2'")
    print ("To list the whole list '3'")
    print ("To exit program: type '4'")
    print ("-------------------------")
    return input ("Choose your option: ")

def addmenu():
    additem = input("Name of list item: ")
    firstlist.append(additem)
    print (additem, "has been appended")

def checkmenu():
    printthis = input("What are you looking for?: ")
    if printthis in firstlist:
        print ("is in the list")
    else:
        print ("is not in the list")

def listlist():
    print (firstlist[1])

# Perform action
loop = 1
choice = 0
while loop == 1:
    choice = int(menu())
    if choice == 1:
        addmenu()
    elif choice == 2:
        checkmenu()
    elif choice == 3:
        listlist()
    elif choice == 4:
        loop = 0
    elif (choice &gt; 4):
        print ("You made an incoorect selection")
</code></pre>
