Here is what ive done:
JavaScript
x
14
14
1
food =["cheeseburger", "smallchips", "drink"]
2
prices =[2.50, 1.50, 1]
3
x=0
4
5
myorderfood=[]
6
myordercost=[]
7
8
print("Burgersn")
9
10
print("Menu:")
11
print("Cheeseburger. Cost - $2.50 each")
12
print("Small chips. Cost - $1.50 each")
13
print("Drink - Cola only. Cost - $1.00 eachn")
14
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. :
JavaScript
1
16
16
1
while True:
2
try:
3
drinkselect = input("Please select which drink:n")
4
if drinkselect == "cola":
5
quantitydrink = int(input("How many would you like?n"))
6
7
except ValueError:
8
print("Not valid")
9
continue
10
11
if drinkselect != "cola":
12
print("Not on our menu!n")
13
else:
14
print("good choicen")
15
break
16
Advertisement
Answer
You can use something like this:
JavaScript
1
39
39
1
from statistics import quantiles
2
from xml.etree.ElementPath import prepare_predicate
3
4
5
food =["cheeseburger", "smallchips", "drink"]
6
prices =[2.50, 1.50, 1]
7
x=0
8
price = 5
9
quantitydrink = 0
10
myorderfood=[]
11
myordercost=[]
12
13
print("Burgersn")
14
15
print("Menu:")
16
print("Cheeseburger. Cost - $2.50 each")
17
print("Small chips. Cost - $1.50 each")
18
print("Drink - Cola only. Cost - $1.00 eachn")
19
print("10% GST applies to total amount (including both food and delivery)")
20
print("Delivery is free for food orders that are $30 or more")
21
print("Delivery cost is an additional $5 for food orders below $30n")
22
while True:
23
try:
24
drinkselect = input("Please select which drink:n")
25
if drinkselect == "cola":
26
quantitydrink += int(input("How many would you like?n"))
27
28
except ValueError:
29
print("Not valid")
30
continue
31
32
if drinkselect != "cola":
33
print("Not on our menu!n")
34
else:
35
print("good choicen")
36
price += 1 * quantitydrink
37
print(f"Your total cost is {price}!")
38
break
39
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:
JavaScript
1
6
1
price = 5 #added this on line 8 because the delivery cost is 5 so that is the base price
2
quantitydrink = 0 #added this on line 9 so you can add the amount to it later in the code
3
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.
4
price += 1 * quantitydrink # added this in line 36 to calculate the price based on how many colas you are ordering and the base price
5
print(f"Your total cost is {price}!") #added this at line 37 to print the final price of the order
6
hope this helps!
FINAL CODE WITH ALL FIXES:
JavaScript
1
93
93
1
from statistics import quantiles
2
from xml.etree.ElementPath import prepare_predicate
3
4
5
finished = False
6
food =["cheeseburger", "smallchips", "drink", "delivery"]
7
prices =[2.50, 1.50, 1, 5]
8
x=0
9
price = 5
10
quantitydrink = 0
11
quantityburger = 0
12
quantitychips = 0
13
quantitydelivery = 0
14
15
myorderfood=[]
16
myordercost=[]
17
18
print("Burgersn")
19
20
print("Menu:")
21
print("Cheeseburger. Cost - $2.50 each")
22
print("Small chips. Cost - $1.50 each")
23
print("Drink - Cola only. Cost - $1.00 eachn")
24
print("10% GST applies to total amount (including both food and delivery)")
25
print("Delivery is free for food orders that are $30 or more")
26
print("Delivery cost is an additional $5 for food orders below $30n")
27
28
name = input("What is your name?n")
29
30
print("nHello " + name + "n")
31
32
while finished == False:
33
try:
34
burgerselect = input("Please select which burger:n")
35
if burgerselect == "cheeseburger":
36
quantityburger += int(input("How many would you like?n"))
37
except ValueError:
38
print("Not valid")
39
continue
40
41
if burgerselect != "cheeseburger":
42
print("Not on our menu!n")
43
else:
44
print("good choicen")
45
price += 2.5 * quantityburger
46
47
try:
48
chipselect = input("Please select what size chips:n")
49
if chipselect == "small":
50
quantitychips += int(input("How many would you like?n"))
51
52
except ValueError:
53
print("Not valid")
54
continue
55
56
if chipselect != "small":
57
print("Not on our menu!n")
58
else:
59
print("good choicen")
60
price += 1.50 * quantitychips
61
62
try:
63
drinkselect = input("Please select which drink:n")
64
if drinkselect == "cola":
65
quantitydrink += int(input("How many would you like?n"))
66
67
except ValueError:
68
print("Not valid")
69
continue
70
71
if drinkselect != "cola":
72
print("Not on our menu!n")
73
else:
74
print("good choicen")
75
price += 1 * quantitydrink
76
77
deliveryselect=input('Would you like delivery? n Yes: Deliveryn No: No delivery n n')
78
if deliveryselect=='Yes'or deliveryselect=='yes':
79
print('Thank Youn')
80
if price <= 30:
81
price += 5
82
elif price > 30:
83
price += 0
84
finished == True
85
break
86
elif deliveryselect =='No' or deliveryselect=='no':
87
print('Thank youn')
88
finished == True
89
break
90
91
92
print(f"Your total cost is {price}!")
93