In: Computer Science
Write a Python program that simulates a restaurant ordering system where it stores multiple orders of a dish and the price for each order stored into a list. The program will then print the receipt which includes list of orders and their price along with the subtotal before tax, the tax amount, and the final total. Also include tip suggestions for 10%, 15% and 20%. Use the format specifiers to make the price line up and the tip only 2 decimal points.
Example:
Welcome to No 2. Kitchen
Order
Lt. Tso Chicken $ 17.50
Half Century Eggs $ 2.50
Durian ice cream $ 5.00
=========================
Subtotal $ 25.00
Tax (7%) $ 1.75
=========================
Total $ 26.75
Tip suggestion
10% : $2.67
15% : $4.01
20% : $5.35
A sample python program which demonstates the above use case scenario is as follows:
(As there were no constrainst given for what to include in the restaurant food menu and pricings, I have prepared a universal template for you. Change the food items or the restaurant name and the other variable parameters as per your convenience)
menu = { "burger":5.00, "fries":3.50, "drink":1.00 }
order = { "burger":0, "fries":0, "drink":0 }
subtotal=0.0
def orderFrom():
global subtotal
while True:
print ("What you want to order today?\n1. Burger\n2. Fries\n3. Drink\n4. Done Ordering (Give me Receipt)")
choice = int(input("Your Choice"))
if choice==1:
order["burger"]+=1
subtotal=subtotal + menu["burger"]
elif choice==2:
order["fries"]+=1
subtotal+=menu["fries"]
elif choice==3:
order["drink"]+=1
subtotal+=menu["drink"]
elif choice==4:
printReceipt()
break
else:
print("Wrong Input")
def printReceipt():
global subtotal
salesTax=7
total=subtotal+(0.07*subtotal)
print("\nYou ordered : ")
print("\n",order["burger"]," Burger(s) : $","{:.2f}".format(order["burger"]*menu["burger"]))
print("\n",order["fries"]," Frie(s) : $","{:.2f}".format(order["fries"]*menu["fries"]))
print("\n",order["drink"]," Drink(s) : $","{:.2f}".format(order["drink"]*menu["drink"]))
print("\n=========================")
print("\nSubtotal : $","{:.2f}".format(subtotal))
print("\nTax (7%) : $", "{:.2f}".format(0.07*subtotal))
print("\n=========================")
print("Total Cost : $","{:.2f}".format(total))
print("Tip Suggestion\n 10% : $","{:.2f}".format(0.1*total),"\n 15% : $","{:.2f}".format(0.15*total),"\n 20% : $","{:.2f}".format(0.2*total))
print("Visit Us Again")
order["burger"]=0
order["fries"]=0
order["drink"]=0
subtotal=0.0
getOrderFunc()
def getOrderFunc():
print("Welcome to ABC Restaurant\n")
getOrder = input ("Do you want to order something(Y/N)?")
if getOrder=='Y'or getOrder=='y':
orderFrom()
else:
print ("Thanks for coming")
exit()
getOrderFunc()
Output:
Hope you find the implementation helpful and insightful.
Keep Learning!