Created
October 24, 2018 13:02
-
-
Save HemantNegi/98394babb3b30484829caefbb637c9cc to your computer and use it in GitHub Desktop.
implement an ATM machine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enter your code here. Read input from STDIN. Print output to STDOUT | |
# DENOMINATIONS: 5 10 20 50 | |
# BILLS: 4 3 1 1 | |
# withdraw(75): return the number of bills/denomination (e.g.: one bill of 5, one bills of 20, one bill of 50) | |
NOTES = { | |
# 1: 10, | |
5: 4, | |
10: 3, | |
20: 1, | |
50: 1 | |
} | |
def withdraw(amount): | |
result = {} | |
notes = NOTES.copy() | |
for x in sorted(NOTES.iterkeys(), reverse=True): | |
while(amount >= x and notes[x] != 0): | |
if x in result: | |
result[x] += 1 | |
else: | |
result[x] = 1 | |
amount = amount - x | |
notes[x] -= 1 | |
# if amount in NOTES: | |
# result[amount] = 1 | |
if amount > 0: | |
return "the amount can not be withdrawn." | |
else: | |
NOTES = notes | |
return result | |
print withdraw(74) | |
print NOTES |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment