-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup-assignment-alt-2.py
More file actions
51 lines (42 loc) · 1.95 KB
/
group-assignment-alt-2.py
File metadata and controls
51 lines (42 loc) · 1.95 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
# create a dictionary whose key is branch and value is an empty array
# the empty array will store all the item totals
kori_supermarket = {'A': [], 'B': [], 'C': [], 'D': [], 'E': []}
# make a list out of the keys in kori supermarket
expected_inputs = kori_supermarket.keys() # = ['A', 'B', 'C', 'D', 'E']
# create an endless loop to take in all supermarkets' data endlessly
while True:
branch = input("Branch: ").upper()
# condition to terminate loop
if branch == "END":
# terminate loop only if we have more than 6 items
if len(kori_supermarket['A']) < 2 or len(kori_supermarket['B']) < 2 or len(kori_supermarket['C']) < 2 or len(kori_supermarket['D']) < 2 or len(kori_supermarket['E']) < 2:
print("Error: Please enter at least six items for all the branches ")
continue
else:
break
# checking if input (branch name) makes sense
if expected_inputs.__contains__(branch):
print("Key in the following data for branch " + branch)
else:
print("Key in the correct branch name")
continue
print(kori_supermarket)
code = input("enter code: ")
unit_price = float(input("Enter unit price: "))
quantity = int(input("Enter quantity: "))
item_price = unit_price * quantity
# update dictionary only if the branch is A/B/C...
if branch != 'END':
kori_supermarket[branch].append(item_price)
print("DATA: " + str(kori_supermarket))
print("Total so far for kori " + branch + " is " + str(sum(kori_supermarket[branch])))
print(" ")
# calculate grand total
grand_total = 0
for branch in kori_supermarket:
branch_total = sum(kori_supermarket[branch])
kori_supermarket[branch] = branch_total
grand_total = grand_total + branch_total
print("Below is each Kori Branch with its subtotal: ")
print(kori_supermarket)
print("The grand total sale for all kori supermarkets is " + str(grand_total))