0

Anyone know how to debug this program? Should be a very quick fix. Thanks!

#Make List ShoppingList = [] print ("Your shopping list is empty.") nextItem = input("What item do you want to add next: ") ShoppingList.append(nextItem) print ("Your shopping list contains: " ) for n in range (0, len(ShoppingList)): print (n + 1 , ". " , (ShoppingList[n])) while Option != 3: print("Do you want to:" + '\n' + " 1. Add an item" + '\n' + " 2. Remove an item" + '\n' + " 3. Quit") Option = int(input("Enter your choice: ")) while Option > 3 or Option < 1: Option = int(input("Not a valid choice, enter your choice: ")) if Option == 2: RemoveItem = input("What item would you like to remove? ") try: ShoppingList.remove(RemoveItem) except ValueError: print ("ERROR: Item is not on list") print ("------------------------" + '\n') print ("Your shopping list contains: " ) for n in range (0, len(ShoppingList)): print (n + 1 , ". " , (ShoppingList[n])) print ('\n') if Option == 1: nextItem = input("What item do you want to add next: ") ShoppingList.append(nextItem) print ("------------------------" + '\n') print ("Your shopping list contains: " ) for n in range (0, len(ShoppingList)): print (n + 1 , ". " , (ShoppingList[n])) print ('\n') FileObject = open("ShoppingList.txt" , 'w') for index in range (0, len(ShoppingList)): FileObject.write (str(ShoppingList[index] + "\n")) FileObject.close() print ("Bye!")

16th May 2021, 11:52 PM
Henry Fournier
Henry Fournier - avatar
7 odpowiedzi
0
Whats the problem? Post your error as well
16th May 2021, 11:57 PM
Slick
Slick - avatar
0
File "/Users/henryfournier/Documents/Classes/Programming/Unit5/wongs.py", line 12, in <module> while Option != 3: NameError: name 'Option' is not defined
17th May 2021, 12:06 AM
Henry Fournier
Henry Fournier - avatar
0
says it right there. the variable 'Option' was never defined, so referencing it raised a Name Error
17th May 2021, 12:10 AM
Slick
Slick - avatar
0
Yes i know, but im not sure where and how I should define that
17th May 2021, 12:18 AM
Henry Fournier
Henry Fournier - avatar
0
Option = ... But its a choice sorta program so mabye the person who uses it should have a choice in what it is
17th May 2021, 12:19 AM
Slick
Slick - avatar
0
option = what
17th May 2021, 12:50 AM
Henry Fournier
Henry Fournier - avatar