Discuss / Python / 交作业

交作业

Topic source

chengww5217

#1 Created at ... [Delete] [Delete and Lock User]
# -*- coding: utf-8 -*-
class Screen(object):

    @property
    def width(self):
        return self.__width

    @width.setter
    def width(self, width):
        if not isinstance(width, (int, float)):
            raise TypeError('the type of width must be int or float')
        self.__width = width

    @property
    def height(self):
        return self.__height

    @height.setter
    def height(self, height):
        if not isinstance(height, (int, float)):
            raise TypeError('the type of height must be int or float')
        self.__height = height

    @property
    def resolution(self):
        return self.__width * self.__height

  • 1

Reply