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
|
#INPUT
QUARTER = 0.25
DIME = 0.10
NICKEL = 0.05
PENNY = 0.01
amount = float(input("Enter a dollar amount?"))
#PROCESS
def coins(total, coin):
if total < coin:
return 0
remainder = round(total % coin, 2)
return round((total - remainder) / coin)
def reduce(total, coin, number_of_coins):
return round(total - (number_of_coins * coin), 2)
def calculate(total):
quarters = coins(total, QUARTER)
total = reduce(total, QUARTER, quarters)
dimes = coins(total, DIME)
total = reduce(total, DIME, dimes)
nickels = coins(total, NICKEL)
total = reduce(total, NICKEL, nickels)
pennies = coins(total, PENNY)
total = reduce(total, PENNY, pennies)
return [quarters, dimes, nickels, pennies]
def receipt(total):
coins = calculate(total)
return f"quarters:{coins[0]}; dimes:{coins[1]}; nickels:{coins[2]}; pennies:{coins[3]}"
#OUTPUT
print(receipt(amount))
|