Discuss / Python / 交作业

交作业

Topic source
# -*-coding:utf-8-*-
class Screen(object):
    @property
    def width(self):
        return self._width

    @width.setter
    def width(self, value):
        if not isinstance(value, int):
            raise TypeError('value must be int')
        self._width = value

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

    @height.setter
    def height(self, value):
        if not isinstance(value, int):
            raise TypeError('value must be int')
        self._height = value

    @property
    def solution(self):
        return self._width*self._height

huawei=Screen()
huawei.width=1024
huawei.height=768
print(huawei.solution)

  • 1

Reply