18 lines
392 B
Python
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
|
|
"""
|