Sichanov

dd

Oct 30th, 2021
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. class Inventory:
  2.     items = []
  3.  
  4.     def __init__(self, capacity: int):
  5.         self.__capacity = capacity
  6.         self.initial_capacity = self.__capacity
  7.  
  8.     def add_item(self, item: str):
  9.         if self.__capacity > 0:
  10.             self.items.append(item)
  11.             self.__capacity -= 1
  12.         else:
  13.             return 'not enough room in the inventory'
  14.  
  15.     def get_capacity(self):
  16.         return self.initial_capacity
  17.  
  18.     def __repr__(self):
  19.         rep = f"Items: {', '.join(self.items)}.\nCapacity left: {self.__capacity}"
  20.         return rep
Advertisement
Add Comment
Please, Sign In to add comment