Complete the code to define the class representing an inventory item.
class InventoryItem: def __init__(self, [1], quantity): self.[1] = [1] self.quantity = quantity
The constructor needs an identifier for the inventory item, commonly called item_id.
Complete the code to add stock to the inventory item.
def add_stock(self, [1]): self.quantity += [1]
The method parameter should represent the amount of stock to add, commonly named amount.
Fix the error in the method to remove stock safely.
def remove_stock(self, amount): if self.quantity [1] amount: self.quantity -= amount else: raise ValueError('Not enough stock')
We must check if current quantity is greater than or equal to the amount to remove.
Fill both blanks to create a dictionary comprehension that maps item IDs to quantities for items with quantity greater than 0.
stock_map = {item.[1]: item.[2] for item in inventory if item.quantity > 0}The dictionary keys should be item IDs and values should be quantities.
Fill all three blanks to create a method that returns a list of item IDs with quantity below a threshold.
def low_stock_items(self, [1]): return [item.[2] for item in self.inventory if item.quantity [3] [1]]
The method takes a threshold and returns item IDs where quantity is less than the threshold.