quitshop = False shoppinglist = ['Carrots', 'Potatoes', 'Onions' ] def printlist (): '''this prints the shopping list''' print (shoppinglist) def additem (): '''This adds a specified item to the list''' additem = input("What would you like to add?: ") shoppinglist.append(additem) return print ("Okay.") def removeitem (): '''This function asks for an item that the user would like to delete from the list, and then checks for the item. If it's in the list, it's deleted. if not, error message shown and returns to the menu''' itemdel = input("What item would you like to delete (Case Sensitive)?: ") if itemdel in shoppinglist: print ("You got it, Chief! Deleting that item") shoppinglist.remove(itemdel) else: print ("I'm sorry but that's not in the list.") while (quitshop == False): #added in to keep refreshing the menu after an action is made/input is made print (" ") print ("menu") print (" ") print ("1 = add item to list") print ("2 = remove an item from list") print ("3 = view list") print ("4 = quit program") userchoice = int(input ("What would you like to do?: ")) if (userchoice ==1): additem () elif (userchoice ==2): removeitem () elif (userchoice ==3): print ("Here's your list, bud:") printlist () elif (userchoice ==4): print ("Seeya!") quit quitshop = True else: print ("Error") print ("Wanna try again?")
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question