Skip to content

Commit 3ca2a45

Browse files
committed
Add coin-regiter module
1 parent d51bc50 commit 3ca2a45

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

coin-register/REAME.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Coin register
2+
3+
Code to manipulate coins value
4+
5+
### Worked concepts
6+
7+
* for loop
8+
* control flow

coin-register/coin_operations.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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

0 commit comments

Comments
 (0)