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
|
QUARTER = 0.25
DIME = 0.10
NICKEL = 0.05
PENNY = 0.01
def calculate_with(total, coin):
remainder = round(total % coin, 2)
return round((total - remainder) / coin)
def calculate(money):
quarters = calculate_with(money, QUARTER)
money = money - (quarters * QUARTER)
dimes = calculate_with(money, DIME)
money = money - (dimes * DIME)
nickels = calculate_with(money, NICKEL)
money = money - (nickels * NICKEL)
pennies = round(money * 100)
return [quarters, dimes, nickels, pennies]
assert [0, 0, 0, 0] == calculate(0.00)
assert [0, 0, 0, 1] == calculate(0.01)
assert [0, 0, 1, 0] == calculate(0.05)
assert [0, 0, 1, 1] == calculate(0.06)
assert [0, 1, 0, 0] == calculate(0.10)
assert [0, 1, 0, 1] == calculate(0.11)
assert [0, 1, 1, 1] == calculate(0.16)
assert [1, 0, 0, 0] == calculate(0.25)
assert [1, 0, 0, 1] == calculate(0.26)
assert [1, 0, 1, 1] == calculate(0.31)
assert [1, 1, 1, 1] == calculate(0.41)
assert [4, 0, 0, 1] == calculate(1.01)
print("All tests are passing!")
|