Last active
December 13, 2018 18:17
-
-
Save ssbozy/5cf9045bf3d72b78b1f3b5b2cc029cd0 to your computer and use it in GitHub Desktop.
Currency Calculator
This file contains hidden or 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
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