Create a `BankAccount` class with a protected `_balance` attribute. Implement methods to deposit and withdraw money with basic validation.
account = BankAccount(100)
account.deposit(50)
account.withdraw(30)
account.display_balance()
Current balance: 120
📚 Protected Attributes Tutorial
Create a `Person` class with private `__age` attribute. Implement proper getter and setter methods with age validation.
person = Person()
person.set_age(25)
print(person.get_age())
person.set_age(150)
25 years
Invalid age!
Create a `Temperature` class that uses @property to control access to celsius value. Add validation to prevent temperatures below absolute zero (-273.15°C).
temp = Temperature()
temp.celsius = 25
print(temp.celsius)
temp.celsius = -300
25
ValueError: Temperature below absolute zero!
📚 Property Decorators Explained
Create a `Circle` class with private `__radius` and read-only `area` property. The area should be calculated when accessed but not modifiable directly.
circle = Circle(5)
print(circle.area)
circle.area = 100
78.53981633974483
AttributeError: can't set attribute
Create a `Student` class that fully encapsulates student data: - Private name (validated to be non-empty) - Private grades list (with methods to add grades and calculate average)
student = Student("Alice")
student.add_grade(90)
student.add_grade(85)
print(student.get_name())
print(student.get_average())
Alice
87.5