Here is what ive done:
food =["cheeseburger", "smallchips", "drink"]
prices =[2.50, 1.50, 1]
x=0
myorderfood=[]
myordercost=[]
print("Burgersn")
print("Menu:")
print("Cheeseburger. Cost - $2.50 each")
print("Small chips. Cost - $1.50 each")
print("Drink - Cola only. Cost - $1.00 eachn")
I want to display an invoice at the end once the user has completed there order showing there total price.
This is some of my code for just the drinks, same type of code used for cheeseburger etc. :
while True:
try:
drinkselect = input("Please select which drink:n")
if drinkselect == "cola":
quantitydrink = int(input("How many would you like?n"))
except ValueError:
print("Not valid")
continue
if drinkselect != "cola":
print("Not on our menu!n")
else:
print("good choicen")
break
Advertisement
Answer
You can use something like this:
from statistics import quantiles
from xml.etree.ElementPath import prepare_predicate
food =["cheeseburger", "smallchips", "drink"]
prices =[2.50, 1.50, 1]
x=0
price = 5
quantitydrink = 0
myorderfood=[]
myordercost=[]
print("Burgersn")
print("Menu:")
print("Cheeseburger. Cost - $2.50 each")
print("Small chips. Cost - $1.50 each")
print("Drink - Cola only. Cost - $1.00 eachn")
print("10% GST applies to total amount (including both food and delivery)")
print("Delivery is free for food orders that are $30 or more")
print("Delivery cost is an additional $5 for food orders below $30n")
while True:
try:
drinkselect = input("Please select which drink:n")
if drinkselect == "cola":
quantitydrink += int(input("How many would you like?n"))
except ValueError:
print("Not valid")
continue
if drinkselect != "cola":
print("Not on our menu!n")
else:
print("good choicen")
price += 1 * quantitydrink
print(f"Your total cost is {price}!")
break
So the base price is 5 for the delivery and if you pick cola it adds the price of the cola multiplied by the amount you purchase to the price variable.
The += operator is best for this.
Changes:
price = 5 #added this on line 8 because the delivery cost is 5 so that is the base price
quantitydrink = 0 #added this on line 9 so you can add the amount to it later in the code
quantitydrink += int(input("How many would you like?n")) # changed this in line 26 to add the amount you are ordering to the initial value.
price += 1 * quantitydrink # added this in line 36 to calculate the price based on how many colas you are ordering and the base price
print(f"Your total cost is {price}!") #added this at line 37 to print the final price of the order
hope this helps!
FINAL CODE WITH ALL FIXES:
from statistics import quantiles
from xml.etree.ElementPath import prepare_predicate
finished = False
food =["cheeseburger", "smallchips", "drink", "delivery"]
prices =[2.50, 1.50, 1, 5]
x=0
price = 5
quantitydrink = 0
quantityburger = 0
quantitychips = 0
quantitydelivery = 0
myorderfood=[]
myordercost=[]
print("Burgersn")
print("Menu:")
print("Cheeseburger. Cost - $2.50 each")
print("Small chips. Cost - $1.50 each")
print("Drink - Cola only. Cost - $1.00 eachn")
print("10% GST applies to total amount (including both food and delivery)")
print("Delivery is free for food orders that are $30 or more")
print("Delivery cost is an additional $5 for food orders below $30n")
name = input("What is your name?n")
print("nHello " + name + "n")
while finished == False:
try:
burgerselect = input("Please select which burger:n")
if burgerselect == "cheeseburger":
quantityburger += int(input("How many would you like?n"))
except ValueError:
print("Not valid")
continue
if burgerselect != "cheeseburger":
print("Not on our menu!n")
else:
print("good choicen")
price += 2.5 * quantityburger
try:
chipselect = input("Please select what size chips:n")
if chipselect == "small":
quantitychips += int(input("How many would you like?n"))
except ValueError:
print("Not valid")
continue
if chipselect != "small":
print("Not on our menu!n")
else:
print("good choicen")
price += 1.50 * quantitychips
try:
drinkselect = input("Please select which drink:n")
if drinkselect == "cola":
quantitydrink += int(input("How many would you like?n"))
except ValueError:
print("Not valid")
continue
if drinkselect != "cola":
print("Not on our menu!n")
else:
print("good choicen")
price += 1 * quantitydrink
deliveryselect=input('Would you like delivery? n Yes: Deliveryn No: No delivery n n')
if deliveryselect=='Yes'or deliveryselect=='yes':
print('Thank Youn')
if price <= 30:
price += 5
elif price > 30:
price += 0
finished == True
break
elif deliveryselect =='No' or deliveryselect=='no':
print('Thank youn')
finished == True
break
print(f"Your total cost is {price}!")