File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ # Coin register
2+
3+ Code to manipulate coins value
4+
5+ ### Worked concepts
6+
7+ * for loop
8+ * control flow
Original file line number Diff line number Diff line change 1+ def num_coins (cents ):
2+
3+ '''
4+ num_coins(33) == 5
5+ 33 => 1 quarter, 1 nickel, 3 pennies => 5 coins
6+ '''
7+
8+ if cents <= 0 :
9+ return 0
10+ remaning_coins = cents
11+ number_of_coins = 0
12+ for _ in range (cents ):
13+ if remaning_coins >= 50 :
14+ number_of_coins += 1
15+ remaning_coins -= 50
16+
17+ elif remaning_coins >= 25 :
18+ number_of_coins += 1
19+ remaning_coins -= 25
20+
21+ elif remaning_coins >= 10 :
22+ number_of_coins += 1
23+ remaning_coins -= 10
24+
25+ elif remaning_coins >= 5 :
26+ number_of_coins += 1
27+ remaning_coins -= 5
28+
29+ elif remaning_coins >= 1 :
30+ number_of_coins += 1
31+ remaning_coins -= 1
32+
33+
34+ return number_of_coins
You can’t perform that action at this time.
0 commit comments