Advertisement
GalinaKG

Inventory

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