From 5d8047027702c07843bc3f173690ca0420cad62d Mon Sep 17 00:00:00 2001 From: Pythoncodist Date: Sat, 13 Sep 2025 18:30:58 -0700 Subject: [PATCH] Initial Commit --- product_class.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/product_class.py b/product_class.py index c1b8a56..e07ed0e 100644 --- a/product_class.py +++ b/product_class.py @@ -1,5 +1,7 @@ class product: - def __init__(self, name: str, price: float, quantity: int = 1): + def __init__(self, name: str, price: float, quantity = 0): + assert price >= 0, "Price must be non-negative" + assert quantity >= 0, "Quantity must be non-negative" self.name = name self.price = price self.quantity = quantity @@ -13,7 +15,8 @@ class product: # Example usage: -product1 = product("Laptop", 1999.99, 1) + +product1 = product("Laptop", 1999.99, -1) print(product1.display_info()) # Output: Item: Laptop, Price: $1999.99 print(product1.calculate_total_price()) # Output: 3999996.0001 product2 = product("Smartphone", 799.99, 3)