Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MoneyBox:
- def __init__(self, capacity): # конструктор с аргументом – вместимость копилки
- self.capacity = capacity
- self.amount = 0
- def can_add(self, v): # True, если можно добавить v монет, False иначе
- if self.capacity >= self.amount + v:
- return True
- else:
- return False
- def add(self, v): # положить v монет в копилку
- if self.can_add(v):
- self.amount += v
- return self.amount
- else:
- return self.amount
Add Comment
Please, Sign In to add comment