-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup-assignment.py
More file actions
48 lines (44 loc) · 1.61 KB
/
group-assignment.py
File metadata and controls
48 lines (44 loc) · 1.61 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
import random
# dictionary contains supermarket name as key and supermarket total as value
kori_supermarket = {
"kori_A": 0,
"kori_B": 0,
"kori_C": 0,
"kori_D": 0,
"kori_E": 0,
}
# We make a list out of the keys of our supermarket dictionary
branch = list(kori_supermarket.keys())
# We loop through the list we created
for key in branch:
price = []
print(f"branch of {key}")
print('enter "end" when you finish')
# We endlessly process the items per supermarket
while True:
code = input("enter code: ").lower()
# We key in end to end the processing of items
if code == "end":
# processing of items ends only ends if we have more than 6 items
if len(price) < 6:
print("Error: Please enter at least six items.")
continue
else:
break
unit_price = float(input("enter unit price: "))
quantity = int(input("enter quantity: "))
item_total = quantity * unit_price
# We append total per item to empty price list
price.append(item_total)
print(f"item total is {item_total}")
print(" ")
# Get the sum of the price array
total_price = sum(price)
kori_supermarket[key] = total_price
print("Total amount for " + key + " is " + str(total_price))
print(" ")
print("Here is each branch with its total : ")
print(kori_supermarket)
# Get the sum of the values of the kori supermarket dictionary (grand total)
grand_total = sum(kori_supermarket.values())
print(f"The grand total is {grand_total}")