daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Oct 19th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Ruchella Kock
  2. # 12460796
  3. # This file defines the Inventory class
  4.  
  5.  
  6. class Inventory(object):
  7.     """
  8.     Keeping an inventory of items
  9.     """
  10.  
  11.     def __init__(self):
  12.         self.inventory = []
  13.  
  14.     def add(self, item):
  15.         """
  16.         Add an item to the inventory (list)
  17.         """
  18.         self.inventory.append(item)
  19.  
  20.     def remove(self, item):
  21.         """
  22.         Remove an item from the inventory (list)
  23.         """
  24.         self.inventory.remove(item)
  25.  
  26.     def __str__(self):
  27.         list_of_string_items = []
  28.         for item in self.inventory:
  29.             list_of_string_items.append(str(item))
  30.         return ",\n".join(list_of_string_items)
  31.  
  32.     def find_item(self, item_name):
  33.         """
  34.         Check if item is in inventory and if it is return that item
  35.         """
  36.         for item in self.inventory:
  37.             if item.name == item_name:
  38.                 return item
  39.  
  40.     def is_empty(self):
  41.         """
  42.         Check if the inventory is empty
  43.         """
  44.         return len(self.inventory) == 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top