This program defines a Python class "student" with the following attributes and methods:
The program then creates an object o of the "student" class and passes 450 as the argument for total. It then prints the total attribute and the result of the average method.
Finally, it sets the value of total to 350, which is considered valid, hence it is set to the new value. The updated values of the total attribute and the result of the average method are then printed.
# Property Method class student: def __init__(self, total): self._total = total def average(self): return self._total / 5.0 def getter(self): return self._total def setter(self, t): if t < 0 or t > 500: print("Invalid Total and can't Change") else: self._total = t total = property(getter, setter) o = student(450) print("Total : ", o.total) print("Average : ", o.average()) o.total = 350 print("Total : ", o.total) print("Average : ", o.average())To download raw file Click Here
Total : 450 Average : 90.0 Total : 350 Average : 70.0
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions