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