>>> class Order:
...
... def __init__(self, discount, total_price, date):
... self.discount = discount
... self.total_price = total_price
... self.date = date
...
... @property
... def discount(self):
... return self.__discount
...
... @discount.setter
... def discount(self, v):
... low, high = 0, 99
... if not low <= v <= high:
... raise ValueError("should be in [{}; {}], "
... "but passed {}".format(low, high, v))
... self.__discount = v
...
>>> order = Order(1, 2, 3)
>>> order.discount
1
>>> order.discount = 10
>>> order.discount
10
>>> order.discount = 100
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 17, in discount
ValueError: should be in [0; 99], but passed 100
>>>
>>> Order(100, 2, 3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in __init__
File "<stdin>", line 17, in discount
ValueError: should be in [0; 99], but passed 100
>>>