Advertisement
roman_gemini

Terminal

Jun 15th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. import math
  2.  
  3. money = {
  4.     500: 1,
  5.     200: 1,
  6.     100: 1,
  7.     50: 5,
  8.     10: 5,
  9.     5: 5
  10. }
  11.  
  12. while True:
  13.     print("")
  14.     print("")
  15.     print("Available banknotes: " +
  16.           ", ".join(str(key) + "(" + str(money[key]) + ")" for key in money if money[key] > 0))
  17.     print("")
  18.  
  19.     try:
  20.         num = int(input("How much money you want to get? "))
  21.     except ValueError:
  22.         print("Invalid value!")
  23.         continue
  24.  
  25.     if num <= 0:
  26.         print("You trying to deposit? Enter positive number!")
  27.         continue
  28.  
  29.     if num % min(money.keys()) != 0:
  30.         print("Value must be multiple of " + str(min(money.keys())))
  31.         continue
  32.  
  33.     package = {}
  34.     for key in sorted(money.keys(), reverse=True):
  35.         if money[key] > 0 and num > 0:
  36.             cnt = min(money[key], math.floor(num / key))
  37.             num = num - key * cnt
  38.             if 0 < cnt <= money[key]:
  39.                 package[key] = cnt
  40.  
  41.     if num == 0:
  42.         for key in sorted(package, reverse=True):
  43.             money[key] -= package[key]
  44.             print("You got " + str(package[key]) + " banknote(s) of " + str(key) + " UAH")
  45.     else:
  46.         print("Sorry! Terminal has no enough money to satisfy you :(")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement