Discuss / Python / 为什么这样输入参数后直接到if中,抛出错误了??

为什么这样输入参数后直接到if中,抛出错误了??

Topic source

下才爽

#1 Created at ... [Delete] [Delete and Lock User]

class Screen(object): @property def width(self): return self._width @width.setter def width(self,width): self._width=width @property def height(self): return self._height @height.setter def height(self,height): self._height=height @property def resolution(self): if (not isinstance(self._width,int)) or (not isinstance(self._height,int)): raise ValueError('width and height must be int') return self._width*self._height s = Screen() s.width=input('please input width\n') s.height =input('please input height\n') print(s.resolution)

下才爽

#2 Created at ... [Delete] [Delete and Lock User]

知道了,因为input输入的是str字符串,不是int的整数。。


  • 1

Reply