'NameError: Variable name is not defined
I am having trouble with some undefined variables in my code for a school assignment using nested loops and functions. Also, if you happen to spot any other errors please lmk.
Code:
shopping_lists = [
['toothpaste', 'q-tips', 'milk'],
['milk', 'candy', 'apples'],
['planner', 'pencils', 'q-tips']
]
customer_input = ''
#prints shopping lists
print(shopping_lists)
print ('')
print("Press '1' to update an item, '2' to view an item, or '3' to view a list")
customer_input = input("What do you want to do? ")
if customer_input == '1':
def update_list(List, Item, newItem):
list = int(input('What list would you like to update? Answer using 1, 2, or 3. ')-1)
print (shopping_lists[list])
itm = int(input('What item would you like to view? ')-1)
print (shopping_lists[list][itm])
newItm = input('What would you like to change the item to? ')
shopping_lists[list][itm] = newItm
update_list(list, itm, newItm)
def view_item():
pass
def view_list():
pass
#While loop
while 'stop' not in customer_input:
update_list(list, itm, newItm)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
