-
Notifications
You must be signed in to change notification settings - Fork 0
/
cash.py
74 lines (47 loc) · 1.22 KB
/
cash.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def get_cents():
while True:
try:
cents = float(input("Change owed: "))
if cents > 0:
break
except ValueError:
pass
return cents
def calculate_quarters(cents):
quarters = 0
while (cents >= 0.25):
cents -= 0.25
quarters += 1
return quarters
def calculate_dimes(cents):
dimes = 0
while (cents >= 0.10):
cents -= 0.10
dimes += 1
return dimes
def calculate_nickels(cents):
nickels = 0
while (cents >= 0.05):
cents -= 0.05
nickels += 1
return nickels
def calculate_pennies(cents):
pennies = 0
while (cents >= 0.01):
cents -= 0.01
pennies += 1
return pennies
def main():
cents = get_cents()
quarters = calculate_quarters(cents)
cents = round(cents - quarters * 0.25, 2)
dimes = calculate_dimes(cents)
cents = round(cents - dimes * 0.10, 2)
nickels = calculate_nickels(cents)
cents = round(cents - nickels * 0.05, 2)
pennies = calculate_pennies(cents)
cents = round(cents - pennies * 0.01, 2)
coins = quarters + dimes + nickels + pennies
print(f"{coins}")
if __name__ == "__main__":
main()