Advertisement
Spocoman

05. Coins

Dec 27th, 2021 (edited)
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. change = int(float(input()) * 100)
  2. counter = 0
  3.  
  4. while change > 0:
  5.     if change >= 200:
  6.         change -= 200
  7.     elif change >= 100:
  8.         change -= 100
  9.     elif change >= 50:
  10.         change -= 50
  11.     elif change >= 20:
  12.         change -= 20
  13.     elif change >= 10:
  14.         change -= 10
  15.     elif change >= 5:
  16.         change -= 5
  17.     elif change >= 2:
  18.         change -= 2
  19.     elif change == 1:
  20.         change -= 1
  21.     counter += 1
  22.  
  23. print(counter)
  24.  
  25. Решение с тернарен оператор:
  26.  
  27. change = int(float(input()) * 100)
  28. counter = 0
  29.  
  30. while change > 0:
  31.     change -= 200 if change >= 200 \
  32.         else 100 if change >= 100 \
  33.         else 50 if change >= 50 \
  34.         else 20 if change >= 20 \
  35.         else 10 if change >= 10 \
  36.         else 5 if change >= 5 \
  37.         else 2 if change >= 2 else 1
  38.  
  39.     counter += 1
  40.  
  41. print(counter)
  42.  
  43. Решение с лист:
  44.  
  45. coins = [200, 100, 50, 20, 10, 5, 2, 1]
  46. change = int(float(input()) * 100)
  47. counter = 0
  48.  
  49. for coin in coins:
  50.     if change >= coin:
  51.         counter += change // coin
  52.         change %= coin
  53.  
  54. print(counter)
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement