SECTION 38 / 48
Seller Portal Inventory
The lecture uses a Product class and a SellerInventory class. seller_inventory_map stores {product_id: count}. add_items_to_inventory adds items, delete_items removes them and raises an exception if the requested number exceeds availability. get_total_items is not yet implemented.
class Product:
def __init__(self, product_id):
self.product_id = product_id
class SellerInventory:
def __init__(self):
self.seller_inventory_map = {}
def add_items_to_inventory(self, product_id, count):
self.seller_inventory_map[product_id] = (
self.seller_inventory_map.get(product_id, 0) + count
)
def delete_items(self, product_id, count):
if count > self.seller_inventory_map.get(product_id, 0):
raise ValueError("Not enough items")
self.seller_inventory_map[product_id] -= count
def get_total_items(self):
pass