Black_Rabbit

Класс копилка

Nov 12th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. class MoneyBox:
  2.     def __init__(self, capacity): # конструктор с аргументом – вместимость копилки
  3.         self.capacity = capacity
  4.         self.amount = 0
  5.  
  6.  
  7.     def can_add(self, v): # True, если можно добавить v монет, False иначе
  8.         if self.capacity >= self.amount + v:
  9.             return True
  10.         else:
  11.             return False
  12.  
  13.     def add(self, v): # положить v монет в копилку
  14.         if self.can_add(v):
  15.             self.amount += v
  16.             return self.amount
  17.         else:
  18.             return self.amount
Add Comment
Please, Sign In to add comment