Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. class MoneyBox:
  2. def __init__(self, capacity): # конструктор с аргументом – вместимость копилки
  3. self.capacity = capacity
  4. self.start = 0
  5.  
  6. def can_add(self, v): # True, если можно добавить v монет, False иначе
  7. if self.start + v <= self.capacity:
  8. return True
  9. else:
  10. return False
  11. def add(self, v): # положить v монет в копилку
  12.  
  13. if can_add():
  14. self.start += v
  15. else:
  16. print ('MoneyBox is full')
  17. mybox = MoneyBox(100)
  18. mybox.add(50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement