From 1d01b93d62eb33f208547fb5898e5277121e753f Mon Sep 17 00:00:00 2001 From: Pythoncodist Date: Sat, 13 Sep 2025 10:15:23 -0700 Subject: [PATCH] Signed-off-by: Pythoncodist --- product_class.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 product_class.py diff --git a/product_class.py b/product_class.py new file mode 100644 index 0000000..c1b8a56 --- /dev/null +++ b/product_class.py @@ -0,0 +1,22 @@ +class product: + def __init__(self, name: str, price: float, quantity: int = 1): + self.name = name + self.price = price + self.quantity = quantity + + def calculate_total_price(self) -> float: + return self.price * self.quantity + + def display_info(self): + return f"Product: {self.name}, Price: ${self.price:.2f}" + + + +# Example usage: +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) +print(product2.display_info()) # Output: Item: Smartphone, Price: $799.99 +print(product2.calculate_total_price()) # Output: 2399.97 +