Skip to content

Instantly share code, notes, and snippets.

@HemantNegi
Created October 24, 2018 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HemantNegi/98394babb3b30484829caefbb637c9cc to your computer and use it in GitHub Desktop.
Save HemantNegi/98394babb3b30484829caefbb637c9cc to your computer and use it in GitHub Desktop.
implement an ATM machine.
# 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