Expected: Product ID: 2, Name: Casual Shirt, Price: $30.00, Quantity Available: 550 Size: M Got: 'Product ID: 2, Name: Casual Shirt, Price: $30.00, Quantity Available: 550\nSize: M' Failed example: plush_toy.get_product_description() Expected: Product ID: 0, Name: Toy Plushie, Price: $25.00, Quantity Available: 50 Got: 'Product ID: 0, Name: Toy Plushie, Price: $25.00, Quantity Available: 50'
class Product:
def __init__(self, product_id, name, price, quantity):
self.product_id = product_id
self.name = name
self.price = round(price, 2)
self.quantity = quantity
def get_product_description(self):
return (f"Product ID: {self.product_id}, "
f"Name: {self.name}, "
f"Price: ${self.price:.2f}, "
f"Quantity Available: {self.quantity}")
class ElectronicProduct(Product):
def __init__(self, product_id, name, price, quantity,warranty_period):
self.warranty_period = warranty_period
super().__init__(product_id,name,price,quantity)
def get_product_description(self):
base_description = super().get_product_description()
return base_description + f"\nWarranty: {self.warranty_period}"
class ClothingProduct(Product):
def __init__(self, product_id, name, price, quantity,size):
self.size = size
super().__init__(product_id,name,price,quantity)
def get_product_description(self):
base_description = super().get_product_description()
return base_description + f"\nSize: {self.size}"
class ShoppingCart:
Shopping Cart:
Product ID: 1, Name: Laptop, Price: $900.00, Quantity Available: 198
Warranty: 2 years
Product ID: 2, Name: Casual Shirt, Price: $27.00, Quantity Available: 548
Size: M
>>> discounted_cart.calculate_total()
927.0
"""
def __init__(self):
self.cart_items = []
def add_to_cart(self, product):
self.cart_items.append(product)
product.quantity -= 1
def display_cart(self):
cart_details = "Shopping Cart:\n"
for item in self.cart_items:
cart_details += item.get_product_description() + "\n"
print(cart_details.strip())
def calculate_total(self):
total = 0
for item in self.cart_items:
total += item.price
return round(float(total),2)
class DiscountedShoppingCart(ShoppingCart):
def __init__(self,discount_percentage):
super().__init__()
self.discount_percentage = discount_percentage
def apply_discount(self):
for item in self.cart_items:
discount = item.price - (item.price * (self.discount_percentage / 100 ))
item.price = round(discount , 2)
"Implements a method get_product_description that prints basic information about the product"
You're probably returning the string



Step by step
Solved in 2 steps with 3 images









