DeaD_EyE

get_coins back

Jun 18th, 2020
1,120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def get_coins(value: int, coins: tuple):
  2.     if not isinstance(value, int):
  3.         raise ValueError("Only Integers are allowed.")
  4.     if not all(isinstance(element, int) for element in coins):
  5.         raise ValueError("Coins must be all integer.")
  6.     result = {}
  7.     for coin in coins:
  8.         multi = value // coin
  9.         if multi:
  10.             value -= coin * multi
  11.             result[coin] = multi
  12.     return result, value
  13.  
  14.  
  15. coins = (100, 50, 20, 10, 5, 2, 1)
RAW Paste Data