-
-
Save KhanMaytok/35d5804fba18cd0bfb2c to your computer and use it in GitHub Desktop.
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
denominations_USD = [ | |
{ 'title': 'Hundred-dollar bill', 'count': 0, 'val': 10000 }, | |
{ 'title': 'Fifty-dollar bill', 'count': 0, 'val': 5000 }, | |
{ 'title': 'Ten-dollar bill', 'count': 0, 'val': 1000 }, | |
{ 'title': 'Five-dollar bill', 'count': 0, 'val': 500 }, | |
{ 'title': 'One-dollar bill', 'count': 0, 'val': 100 }, | |
{ 'title': 'Quarter', 'count': 0, 'val': 25 }, | |
{ 'title': 'Dime', 'count': 0, 'val': 10 }, | |
{ 'title': 'Nickel', 'count': 0, 'val': 5 }, | |
{ 'title': 'penny', 'count': 0, 'val': 1 } | |
] | |
def currency_converter( amount=0, units=[] ): | |
amount *= 100 | |
for unit in units: | |
while( amount != 0 and amount >= unit['val'] ): | |
amount -= unit['val'] | |
unit['count'] += 1 | |
return units | |
def currency_display( amount=0, units=denominations_USD ): | |
units = currency_converter( amount , units ) | |
for unit in units: | |
if unit['count'] == 0: continue | |
t = [ unit['count'], unit['title'], '\'s' if unit['count'] > 1 else '' ] | |
print( '{} {}{}'.format(*t) ) | |
return None | |
currency_amount = float( input('Convert: ') ) | |
currency_display( currency_amount ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment