-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise37.py
More file actions
42 lines (30 loc) · 941 Bytes
/
Copy pathExercise37.py
File metadata and controls
42 lines (30 loc) · 941 Bytes
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
def makeChange(amount: int) -> dict:
"""
Return the amount of quartes dimes nickels and pennies in dict
:param amount: amount in int
:type amount: int
:raise TypeError: If amount is not a int
:return: dict
:rtype: dict
"""
change = {}
if amount == 0:
return change
if amount // 25 != 0:
change["quarters"] = amount // 25
amount = amount % 25
if amount // 10 != 0:
change["dimes"] = amount // 10
amount = amount % 10
if amount // 5 != 0:
change["nickels"] = amount // 5
amount = amount % 5
if amount // 1 != 0:
change["pennies"] = amount
return change
...
assert makeChange(30) == {"quarters": 1, "nickels": 1}
assert makeChange(10) == {"dimes": 1}
assert makeChange(57) == {"quarters": 2, "nickels": 1, "pennies": 2}
assert makeChange(100) == {"quarters": 4}
assert makeChange(125) == {"quarters": 5}