Discuss / Python / 交作业

交作业

Topic source

Nectar

#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 not isinstance(value, int):

            raise ValueError('width must be an integer!')

        if value < 0:

            raise ValueError('width must greater than 0')

        self._width = value

    @property

    def height(self):

        return self._height

    @height.setter

    def height(self, value):

        if not isinstance(value, int):

            raise ValueError('height must be an integer!')

        if value < 0:

            raise ValueError('height must greater than 0')

        self._height = value

    @property

    def resolution(self):

        return self._width* self._height


  • 1

Reply