In: Computer Science
For python!
You walk into a fast food restaurant and order fries, a burger, and a drink. Create a simple text based user interactive program keeps track of the menu items you order. Use a dictionary to keep track of your menu items and price and another dictionary to keep track of your order and quantity.
Fries are $3.50
Burger are $5.00
Drinks are $1.00
Sales tax rate is 7.25%
menu = { "burger":5.00, "fries":3.50, "drink":1.00 }
order = { "burger":0, "fries":0, "drink":0 }
i. Use menu for the menu items and price. Use order to keep a running total of the number of items ordered.
ii. Keep a running subtotal.
iii. When all items are ordered, calculate the sales tax and total amount.
iv. Print a simple receipt.
v. See the assignment description for a sample video of how this might function.
Python Code for the given problem statement is as follows:
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.25
total=subtotal+(0.725*subtotal)
print("\nYou ordered ",order["burger"]," Burgers + ",order["fries"]," Fries + ",order["drink"]," Drink(s)")
print("Total Cost : ",total, " $")
print("Visit Us Again")
order["burger"]=0
order["fries"]=0
order["drink"]=0
subtotal=0.0
getOrderFunc()
def getOrderFunc():
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:
I Hope you find this solution helpful.
Keep Learning!