Final fix to exact change

This commit is contained in:
Joe S 2021-01-23 19:36:45 -05:00
parent d27d5025fb
commit ab881dd578
1 changed files with 26 additions and 10 deletions

View File

@ -5,20 +5,36 @@ except ValueError:
exit()
change = []
coins = [
['Dollars', 'Dollar'],
['Quarters', 'Quarter'],
['Dimes', 'Dime'],
['Nickels', 'Nickel'],
['Pennies', 'Penny']]
while user_cents > 100:
while user_cents >= 100:
user_cents -= 100
change.append('Dollar')
while user_cents > 25:
change.append(coins[0])
while user_cents >= 25:
user_cents -= 25
change.append('Quarter')
while user_cents > 10:
change.append(coins[1])
while user_cents >= 10:
user_cents -= 10
change.append("Dime")
while user_cents > 5:
change.append(coins[2])
while user_cents >= 5:
user_cents -= 5
change.append("Nickel")
change.append(coins[3])
for _i in range(user_cents):
change.append("Penny")
change.append(coins[4])
if len(change) != 0:
for coin in coins:
num_coins = change.count(coin)
if num_coins != 0:
if num_coins > 1:
print('{0} {1}'.format(num_coins, coin[0]))
else:
print('{0} {1}'.format(num_coins, coin[1]))
else:
print('No change ')
print(change)