forked from course-work/week1
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
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 )
|