Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Cashier:
- num = [5000, 2000, 1000, 500, 200, 100, 50, 10, 5, 1]
- n = len(num)
- cash = [0] * n
- overall = 0
- def set_data(self, s):
- self.overall = 0
- s = s.split(',')
- for e in s:
- val, cnt = map(int, e.split('-'))
- self.cash[self.num.index(val)] = cnt
- self.overall += val * cnt
- def show_total_amount(self):
- print('Всего в кассе', self.overall, 'руб.')
- for i in range(self.n - 1, -1, -1):
- if self.cash[i]:
- print(self.num[i], '-', self.cash[i])
- print()
- def sell_product(self, price, income):
- cash_buf = self.cash.copy()
- change = income - price
- if change < 0:
- print('Недостаточно средств. Операция отклонена.')
- print()
- return
- for i in range(self.n):
- self.cash[i] += income // self.num[i]
- income = income % self.num[i]
- change_cash = [0] * self.n
- for i in range(self.n):
- x = min(change // self.num[i], self.cash[i])
- change_cash[i] += x
- change -= x * self.num[i]
- self.cash[i] -= x
- if change:
- print('Не хватило валюты! Касса не может выдать оставшиеся', change, 'руб.')
- print('Пополните кассе и повторите операцию')
- print()
- self.cash = cash_buf.copy()
- return
- for i in range(self.n - 1, -1, -1):
- if change_cash[i]:
- print(self.num[i], '-', change_cash[i])
- print()
- cashier = Cashier()
- request = input()
- while request != '0':
- if request[0] == '1':
- cashier.set_data(request[2:])
- elif request[0] == '2':
- price, income = map(int, request[2:].split())
- cashier.sell_product(price, income)
- elif request == '3':
- cashier.show_total_amount()
- else:
- print('Неверный запрос.')
- print()
- request = input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement