Advertisement
Lyuben_Andreev

classPhone

Jul 29th, 2024
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | Software | 0 0
  1. class Item:
  2.     def __init__(self, name: str, price: float, quantity=0):
  3.  
  4.         assert price >= 0, f"Price {price} is not greater than zero!"
  5.         assert quantity >= 0, f"Quantity {quantity} is not greater than zero!"
  6.  
  7.         self.name = name
  8.         self.price = price
  9.         self.quantity = quantity
  10.  
  11.     def calculateTotalPrice(self):
  12.         return self.price * self.quantity
  13.  
  14.  
  15. item1 = Item("Phone", 100, 1)
  16. item2 = Item("Laptop", 1000, 3)
  17.  
  18. print(item1.calculateTotalPrice())
  19. print(item2.calculateTotalPrice())
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement