Complete the code to declare a Product class with a constructor.
class Product: def __init__(self, id, name, price): self.id = id self.name = name self.price = [1]
The constructor assigns the price parameter to the instance variable self.price.
Complete the code to add a product to the Cart's items list.
class Cart: def __init__(self): self.items = [] def add_product(self, product): self.items.[1](product)
To add an item to a list in Python, use the append method.
Fix the error in the Order class constructor to correctly assign the cart parameter.
class Order: def __init__(self, order_id, cart): self.order_id = order_id self.cart = [1]
The constructor should assign the passed cart parameter to the instance variable self.cart.
Fill both blanks to create a method that calculates the total price of items in the cart.
class Cart: def __init__(self): self.items = [] def total_price(self): return sum(item.[1] for item in self.[2])
The method sums the price attribute of each item in the items list.
Fill all three blanks to create an Order method that returns a dictionary of product names and their quantities.
class Order: def __init__(self, order_id, cart): self.order_id = order_id self.cart = cart def product_quantities(self): quantities = {} for item in self.cart.[1]: name = item.[2] quantities[name] = quantities.get(name, 0) + [3] return quantities
The method loops over items in the cart, uses the product name as key, and increments the count by 1.