Discuss / Python / 复杂的写法(1)

复杂的写法(1)

Topic source

Zflyee

#1 Created at ... [Delete] [Delete and Lock User]
  • 提交了作业之后,发现大家的写法都比我这个代码量用的少
class Screen(object):
    @property
    def width(self):
        return self._width
    @width.setter
    def width(self, value):
        if value < 0:
            raise ValueError('The value must greater than 0!')
        self._width = value

    @property
    def height(self):
        return self._height
    @height.setter
    def height(self, value):
        if value < 0:
            raise ValueError('The value must greater than 0!')
        self._height = value


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

  • 1

Reply