|
| 1 | +class Mobile: |
| 2 | + def __init__(self, brand, price): |
| 3 | + print("Inside the Mobile constructor") |
| 4 | + self.brand = brand |
| 5 | + self.price = price |
| 6 | + self.total_price = None |
| 7 | + |
| 8 | + def purchase(self): |
| 9 | + if self.brand == "Apple": |
| 10 | + discount = 10 |
| 11 | + else: |
| 12 | + discount = 5 |
| 13 | + self.total_price = self.price - self.price * discount / 100 |
| 14 | + print("Total price of", self.brand, "mobile is", self.total_price) |
| 15 | + |
| 16 | + def return_product(self): |
| 17 | + print("Refund Amount for", self.brand, "mobile is", self.total_price) |
| 18 | + |
| 19 | +class Shoe: |
| 20 | + def __init__(self, material, price): |
| 21 | + print("Inside the Shoe constructor") |
| 22 | + self.material = material |
| 23 | + self.price = price |
| 24 | + self.total_price = None |
| 25 | + |
| 26 | + def purchase(self): |
| 27 | + if self.material == "leather": |
| 28 | + tax = 5 |
| 29 | + else: |
| 30 | + tax = 2 |
| 31 | + self.total_price = self.price + self.price * tax / 100 |
| 32 | + print("Total price of", self.material, "shoe is", self.total_price) |
| 33 | + |
| 34 | + def return_product(self): |
| 35 | + print("Refund Amount for", self.material, "shoe is", self.total_price) |
| 36 | + |
| 37 | +mob1=Mobile("Apple", 20000) |
| 38 | +mob2=Mobile("Samsung", 10000) |
| 39 | + |
| 40 | +shoe1=Shoe("leather",3000) |
| 41 | +shoe2=Shoe("canvas",200) |
| 42 | + |
| 43 | +mob1.purchase() |
| 44 | +mob2.purchase() |
| 45 | + |
| 46 | +shoe1.purchase() |
| 47 | +shoe2.purchase() |
| 48 | + |
| 49 | +mob2.return_product() |
| 50 | + |
| 51 | +shoe1.return_product() |
0 commit comments