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 +