Discuss / Python / 就像以前的数学作业,照着类似的题目模板抄一次,不知道对在哪,也不知道错在哪。。

就像以前的数学作业,照着类似的题目模板抄一次,不知道对在哪,也不知道错在哪。。

Topic source

class Screen(object):

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

@width.setter
def birth(self,value):
    if isinstance(width, int) and width > 0:
        self._birth == value
    else:
        print('不对')

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

@height.setter
def height(self,value):
    if isinstance(height,int) and height>0:
        self._height == value
    else:
        print('高错了')
@property
def resolution(self):
    print('resolution = ',self._height*self._width)

test:

s = Screen() s._width = 1024 s._height = 768 print(s.resolution) assert s.resolution == 786432, '1024 * 768 = %d ?' % s.resolution

你的birth都没改


  • 1

Reply