Original Post
Hey everyone, I'm trying to make a program where you enter what all you need to get from the grocery store. It then put's those items into a list, sorts the list than prints the list. This is the code I have as of right now..
def menu():
print "Welcome"
print "What would you like to do?"
print " "
print "1) Create"
print "2) Quit"
return input("Choose an option: ")
list = []
def add(raw_input):
list.append( (raw_input) )
loop = 1
choice = 0
while loop == 1:
choice = menu()
if choice == 1:
add(raw_input("Enter an item: "))
q = raw_input("Would you like to add another item? y/n: ")
if q == y:
add(raw_input("Enter an item: "))
if q == n:
loop = 0
elif choice == 2:
loop = 0
print "end"
When I run it, it runs normally, It allows me to enter my first item, and it puts it into the list, it than ask, "would you like to add another item? y/n
and if i hit either y or n it gives me this error..
Traceback (most recent call last):
File "C:\Python24\test1", line 23, in -toplevel-
if q == y:
NameError: name 'y' is not defined
I thought since i was using q = raw_input I figured it would work, i'm not too sure whats wrong. Can anyone help?
def menu():
print "Welcome"
print "What would you like to do?"
print " "
print "1) Create"
print "2) Quit"
return input("Choose an option: ")
list = []
def add(raw_input):
list.append( (raw_input) )
loop = 1
choice = 0
while loop == 1:
choice = menu()
if choice == 1:
add(raw_input("Enter an item: "))
q = raw_input("Would you like to add another item? y/n: ")
if q == y:
add(raw_input("Enter an item: "))
if q == n:
loop = 0
elif choice == 2:
loop = 0
print "end"
When I run it, it runs normally, It allows me to enter my first item, and it puts it into the list, it than ask, "would you like to add another item? y/n
and if i hit either y or n it gives me this error..
Traceback (most recent call last):
File "C:\Python24\test1", line 23, in -toplevel-
if q == y:
NameError: name 'y' is not defined
I thought since i was using q = raw_input I figured it would work, i'm not too sure whats wrong. Can anyone help?