Read the code carefully
class Positive:
def __set_name__(self, owner, name: str) -> None:
self.name = name
def __get__(self, instance, owner):
if instance is None:
return self
return instance.__dict__[self.name]
def __set__(self, instance, value) -> None:
if not isinstance(value, int) or value <= 0:
raise ValueError(f"{self.name} must be positive int, got {value!r}")
instance.__dict__[self.name] = value
class Account:
balance = Positive()
age = Positive()
a = Account()
a.balance = 100
a.age = 30
print(a.balance, a.age)
try:
a.balance = -5
except ValueError as e:
print(f"rejected: {e}")
# Class-level access returns the descriptor itself, not a value
print(type(Account.balance).__name__)
# Per-instance values are independent
b = Account()
b.balance = 200
print(a.balance, b.balance)
What will the program print? Write here: