Advertisement
HasteBin0

Python Change Coins

Oct 7th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. def exact_change(change):
  2.     coins = []
  3.     def add(denomination):
  4.         nonlocal coins, change
  5.         full, change = int(change // denomination), int(change % denomination)
  6.         coins.append(full)
  7.     add(100)
  8.     add(25)
  9.     add(10)
  10.     add(5)
  11.     add(1)
  12.     return coins
  13.  
  14. if __name__ == '__main__':
  15.     input_val = float(input())
  16.     if input_val <= 0 or input_val % 100 == 0: print("no change")
  17.     else:
  18.         for (ns, np), c in zip(
  19.             (('dollar', 'dollars'), ('quarter', 'quarters'), ('dime', 'dimes'), ('nickel', 'nickels'), ('penny', 'pennies')),
  20.             exact_change(input_val)
  21.         ):
  22.             if c > 0:
  23.                 print(c, ns if c == 1 else np)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement