Skip to content

Instantly share code, notes, and snippets.

@ssbozy
Last active December 13, 2018 18:17
Show Gist options
  • Save ssbozy/5cf9045bf3d72b78b1f3b5b2cc029cd0 to your computer and use it in GitHub Desktop.
Save ssbozy/5cf9045bf3d72b78b1f3b5b2cc029cd0 to your computer and use it in GitHub Desktop.
Currency Calculator
import sys
class CurrencyCalculator:
def __init__(self, check_cash):
self.check_cash = check_cash
# base_cash should be sorted list with highest currency denomination to lowest
self.base_cash = [100, 50, 20, 10, 5, 1]
self.result = self._breakdown()
def _breakdown(self):
result = []
temp = self.check_cash
for each in self.base_cash:
if temp/each > 0:
result.append(["${}".format(each), temp/each])
temp = temp % each
return result
def __str__(self):
return str(self.result)
cc = CurrencyCalculator(32456)
print cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment