class Screen: def __init__(self, width, height): self.__width = width self.__height = height @property def width(self): return self.__width @width.setter def width(self, width): if not isinstance(width, float): raise ValueError("Variable 'width' must be float") self.__width = width @property def height(self): return self.__height @height.setter def height(self, height): if not isinstance(height, float): raise ValueError("Variable 'height' must be float") self.__height = height @property def resolution(self): return self.width * self.height screen = Screen(10.0, 10.0) # screen.width = 21.0 # screen.height = 2.0 print(screen.resolution)
Sign in to make a reply
风逝紫玄