In: Computer Science
print a menu so that the user can then order from that menu. The user will enter each item they want until they are done with the order. At the end you will print the items the user ordered with their price and the total.
Note: You will be storing your menu items (pizza, burger, hotdog, salad) and your prices (10, 7, 4, 8) in separate lists.
Menu 0) pizza $10 1) burger $7 2) hotdog $4 3) salad $8 Enter the number of the item you want to order: 0 Are you done ordering? (yes or no) no Enter the number of the item you want to order: 2 Are you done ordering? (yes or no) no Enter the number of the item you want to order: 2 Are you done ordering? (yes or no) no Enter the number of the item you want to order: 3 Are you done ordering? (yes or no) yes Final order: pizza @ $10 hotdog @ $4 hotdog @ $4 salad @ $8 Total price: $26
Source Code:
Output:
Code in text format (See above image of code for indentation):
#menu and prices are stored in two separate lists
menu=["pizza","burger","hotdog","salad"]
prices=[10,7,4,8]
#orders and its prices lists
order=[]
p=[]
#total amount
total=0
#print menu
print("Menu")
for i in range(len(menu)):
print(i,")",menu[i],"\t$",prices[i])
while(True):
#read options from user
option=int(input("Enter the number of the item you want to order:
"))
#add order and its price to lists
order.append(menu[option])
p.append(prices[option])
#calculate total
total+=prices[option]
#ask user to stop or to continue
ch=input("Are you done ordering?(yes or no) ")
#if yes break
if(ch=="yes"):
break
print()
#print final order
print("Final order:")
for i in range(len(order)):
print(order[i]," @ $",p[i],sep='')
#print total
print("Total price:$",total)