stuff to do

This commit is contained in:
2016-01-03 11:25:02 -05:00
commit bc46c80b02
11 changed files with 219 additions and 0 deletions

18
02-currency/README.md Normal file
View File

@ -0,0 +1,18 @@
Float to Currency
==================
Write a method that gives the number of American coins and bills needed to represent that number (rounded to the nearest 1/100, i.e. the nearest penny).
As an exmaple, if the float is 12.33, the result would be 1 $10, 2 $1 bills, 1 quarter, 1 nickel and 3 pennies.
Use the following as denominations for your currencies:
Penny: 1 cent
Nickel: 5 cent
Dime: 10 cent
Quarter: 25 cent
One-dollar bill
Five-dollar bill
Ten-dollar bill
Fifty-dollar bill
Hundred-dollar bill

35
02-currency/currency.py Normal file
View File

@ -0,0 +1,35 @@
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 )