Advertisement
vmeansdev

Coin counter

Dec 27th, 2019
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. RUBLES = 1
  2. KOPS = 0
  3.  
  4. def pluralize(value, coin_type):
  5.     div_result = value % 10
  6.     if div_result == 1:
  7.         return 'рубль' if coin_type == RUBLES else 'копейка'
  8.     if value in range(11, 20) or div_result == 0 or div_result in range(5, 10):
  9.         return 'рублей' if coin_type == RUBLES else 'копеек'
  10.     if div_result in range(2, 5):
  11.         return 'рубля' if coin_type == RUBLES else 'копейки'
  12.  
  13. def count(coins):
  14.     rubles_val = coins // 100
  15.     kops_val = coins % 100
  16.     rubles = ''
  17.     kops = ''
  18.     if rubles_val != 0:
  19.         rubles = str(rubles_val) + ' ' + pluralize(rubles_val, RUBLES).upper()
  20.         print(rubles)
  21.     if kops_val != 0:
  22.         kops = str(kops_val) + ' ' + pluralize(kops_val, KOPS).upper()
  23.         print(kops)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement