Files
adii1823 b6eb3ef8a7 ch06
2021-10-28 17:38:47 +05:30

18 lines
392 B
Python

# oop/class.price.py
class Price:
def final_price(self, vat, discount=0):
"""Returns price after applying vat and fixed discount."""
return (self.net_price * (100 + vat) / 100) - discount
p1 = Price()
p1.net_price = 100
print(Price.final_price(p1, 20, 10)) # 110 (100 * 1.2 - 10)
print(p1.final_price(20, 10)) # equivalent
"""
$ python class.price.py
110.0
110.0
"""