Discuss / Python / 作业

作业

Topic source
class Screen(object):
    @property
    def width(self):
        return self._width
    @width.setter
    def width(self, value):
        if not isinstance(value, (float, int)):
            raise TypeError('width type error')
        elif value <= 0 or value > 200:
            raise ValueError('value can not <=0 or > 200')
        else:
            self._width = value
    @property
    def resolution(self):
        return 'enmmmmmmmm'
s = Screen()

s.width = 16
print(s.width)
print(s.resolution)

  • 1

Reply