Signed-off-by: Pythoncodist <donaldcalloway@hey.com>
This commit is contained in:
parent
633968fb77
commit
1d01b93d62
22
product_class.py
Normal file
22
product_class.py
Normal file
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user