Complete the code to define a getter method for the attribute 'name'.
class Person: def __init__(self, name): self._name = name def get_name(self): return self.[1]
The getter method returns the private attribute _name using self._name. Since self. is already in the code, you need to write _name after it, so the full expression is self._name.
Complete the code to define a setter method for the attribute 'age'.
class Person: def __init__(self, age): self._age = age def set_age(self, age): self.[1] = age
The setter method assigns the new value to the private attribute _age. Since self. is already in the code, you need to write _age after it, so the full expression is self._age.
Fix the error in the setter method to correctly update the private attribute '_salary'.
class Employee: def __init__(self, salary): self._salary = salary def set_salary(self, salary): [1] = salary
The setter method must assign the new value to self._salary. Without self., the assignment only creates a local variable and does not update the attribute.
Fill both blanks to create a property for 'height' with getter and setter methods.
class Person: def __init__(self, height): self._height = height @property def height(self): return self.[1] @height.setter def height(self, value): self.[2] = value
The getter returns the private attribute _height. The setter assigns the new value to the same private attribute _height. Both blanks should be filled with _height.
Fill all three blanks to create a property 'weight' with getter, setter, and a condition to allow only positive values.
class Person: def __init__(self, weight): self._weight = weight @property def weight(self): return self.[1] @weight.setter def weight(self, value): if value [2] 0: self.[3] = value
The getter returns self._weight. The setter checks if the new value is greater than zero, then assigns it to self._weight. So blanks are _weight, >, and _weight.