pizzas = { "Margherita" : 9.99, "Mighty Meaty" : 12.99, "Vegetarian Supreme": 10.99, "Hawaiian": 11.99 } order=[] running_total=[] #calls the function to see whether the pizza exists #This will loop round until the function returns a pizza name #Once a valid pizza is found, the while loop will exit and the menu item will be added to the order #Print the order to see what is happening so far. #find the correct pizza and adds the price to the running total list #calls the nextOrder function to see whether the user wants another pizza def placeOrder(): order_item=raw_input("What would you like?") print menuCheck(order_item) while menuCheck(order_item)==None: order_item=raw_input("Sorry, this is not on the menu. Try something else") order.append(order_item) print order for i in pizzas: if i==order_item: running_total.append(pizzas[i]) print running_total nextOrder() #Asks the user if they want to order again #lower used to make user input lower caase. #If the user says yes, then call the place order function def nextOrder(): user_input=raw_input("Would you like to place another order") if user_input.lower()=="y": placeOrder() #This function is used in conjunction with placeOrder #If the user has entered a valid pizza, then it will return the value of order_item back to the order #if not, the the function will return nothing def menuCheck(order_item): for i in pizzas: if order_item == i: return order_item #Set the total to 0 #loop through the running_total list #Each time increment the value of i to the total def checkout(): total = 0 for i in running_total: total+=i print total print "Welcome to Bitz 'n' Pizzas - The number one Pizza service. Select an item from our menu below:" print pizzas ## ###prints one line of the dictionary at a time ##for i in pizzas.iteritems(): ## print i ## ###concatenates the dictionary items together ##for i in pizzas: ## print str(i) + " " + str(pizzas[i]) for i in pizzas: print i print pizzas[i] placeOrder() checkout()
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