-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 2 Question 1.py
More file actions
85 lines (62 loc) · 2.19 KB
/
Assignment 2 Question 1.py
File metadata and controls
85 lines (62 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#COMPLETED
#TESTED
"""
The canteen in the Institute maintains has a table of prices of items, like:
Samosa: 15
Idli: 30
Maggie: 50
Dosa, 70
…
For the program you have to write, set the menu in your program by this statement
(feel free to add more items).
menu = [("Samosa", 15), ("Idli", 30), ("Maggie", 50), ("Dosa", 70), ("Tea", 10),
("Coffee", 20), ("Sandwich", 35), ("ColdDrink", 25)]
Write a program to take a user's order on a terminal and compute the bill.
First show the menu by printing the menu.
For ordering an item, the user inputs the item number and the quantity desired
(e.g. an input can be: 3 1 followed by 1 5 ).
The program should prompt the user to order more,
till he/she hits return (without any numbers) - which is the end of the order.
Print a bill for this order in the form (for the input example above):
Maggie, 1, Rs 50
Samosa, 5, Rs 75
TOTAL, 6 items, Rs 125
"""
menu = [("Samosa", 20), ("Idli", 100), ("Maggi", 25), ("Dosa", 70), ("Tea", 10), ("Coffee", 50), ("Sandwich", 60), ("Cold Drink", 30)]
print("Menu:")
print("")
for i in range(1,len(menu)+1):
print(str(i)+") ",end='')
for j in menu[i-1]:
print(str(j)+" ",end='')
print("")
order = []
items = []
prices = []
print("If you enter one value, there will be an Index Error.\nIf you enter more than two values, only the first two will be considered.")
while(True):
item = list(map(int,input("Order (Item Quantity): ").split()))
if item==[]:
break
elif item[0]<1 or item[0]>8:
print("Invalid Input.") #program will return bill of items before invalid input
continue
else:
items.append(item)
print("")
for i in items:
try:
item = i[0]-1
order.append(menu[item][0])
prices.append(menu[item][1])
except IndexError:
pass
print("Bill: ")
total = 0
total_qt = 0
for i in range(len(order)):
print(order[i] + ", " + str(items[i][1]) + ", Rs. " + str(prices[i]*items[i][1]))
total += prices[i]*items[i][1]
total_qt += items[i][1]
print("")
print("Total: " + str(total_qt) + " Items, Rs. " + str(total))