def buy(self, payment: Payment, kind_of_drink: Type[Drink]): try: return self._buy(payment, kind_of_drink) except Exception as e: print(e) self._change += payment.amount() return None
def refund(self, payment: Payment, price: int): currencies = payment.get_currencies() if len(currencies) != 1: raise RuntimeError('payment should be a currency') payment_amount = payment.amount() if (payment_amount != 100) and (payment_amount != 500): raise RuntimeError('payment should be 100 or 500') if payment_amount == 500 and self._currency_collections[Yen100Coin] < 4: raise RuntimeError('Not enouhg 100 coin for change') change = 0 if payment_amount == 100: self._currency_collections[Yen100Coin] += 1 change = 0 if payment_amount == 500: self._currency_collections[Yen100Coin] -= (payment_amount - 100) / 100 change += (payment.amount() - price) return change