Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- change_types = {25: "Quarter", 10: "Dime", 5: "Nickel", 1: "Penny"}
- def change(cents): # returns change in coins
- coin_values = [25, 10, 5, 1]
- coins = {25: 0, 10: 0, 5: 0, 1: 0}
- def findNext(): # finds next largest coin type
- for coin_val in coin_values:
- if cents >= coin_val: return coin_val
- while cents > 0: # repeats adding coins until 0 cents
- nextCoin = findNext()
- if nextCoin:
- cents -= nextCoin
- coins[nextCoin] += 1
- return coins
- def change_text(change_dic): # makes coin dictionary look nicer
- new_dic = {}
- for coin_value, coin_quantity in change_dic.items():
- new_dic[change_types[coin_value]] = coin_quantity
- return new_dic
- coins = change(55)
- print(change_text(coins))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement