-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
40 lines (32 loc) · 1.17 KB
/
test.py
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
def process_transactions(purchase_orders):
leftovers = list()
for order in purchase_orders:
try:
leftovers.append(purchase_item(order['price'], order['gold_available']))
except:
pass
return leftovers
# Don't edit below this line
def main():
print("Processing transactions...")
leftovers = process_transactions(
[
{"price": 10.00, "gold_available": 125.00},
{"price": 5.00, "gold_available": 2.00},
{"price": 20.01, "gold_available": 5.20},
{"price": 1.04, "gold_available": 254.00},
{"price": 40.20, "gold_available": 6.00},
{"price": 16.00, "gold_available": 235.01},
{"price": 10.70, "gold_available": 10.70},
{"price": 12.00, "gold_available": 2.30},
]
)
print("Transactions complete!")
print("Leftover amounts for successful purchases:")
for leftover in leftovers:
print(f" * {leftover:.2f}")
def purchase_item(price, gold_available):
if gold_available < price:
raise Exception(f"{gold_available:.2f} is not enough for {price:.2f}")
return gold_available - price
main()