krutmaster

Practice task 5

Jun 20th, 2022 (edited)
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. def check_comb(price: int, count: int, step=0):
  2.     if step == 0 and (price < 1 or count < 1) or price < 0 and count < 0:
  3.         raise ValueError('Цена и количество монет должны быть натуральными числами!')
  4.     price -= step
  5.     if count == price == 0:
  6.         if price + count > 0:
  7.             return price + step, count + 1
  8.         return 0, 0
  9.     if price >= 25:
  10.         price, count = check_comb(price, count - 1, 25)
  11.     if count > 0 and price >= 10:
  12.         price, count = check_comb(price, count - 1, 10)
  13.     if count > 0 and price >= 5:
  14.         price, count = check_comb(price, count - 1, 5)
  15.     if count > 0 and price >= 1:
  16.         price, count = check_comb(price, count - 1, 1)
  17.     if step == 0:
  18.         if price + count > 0:
  19.             return False
  20.         return True
  21.     if price + count > 0:
  22.         return price + step, count + 1
  23.     return 0, 0
  24.  
  25.  
  26. if __name__ == '__main__':
  27.     price = int(input('Искомая сумма в центах\n'))
  28.     count = int(input('Количество монет\n'))
  29.     res = check_comb(price, count)
  30.     if res:
  31.         print('Можно')
  32.     else:
  33.         print('Нельзя')
Add Comment
Please, Sign In to add comment