我在一个类中嵌入了以下代码。每当我运行 distToPoint 时,它都会给出错误“unsupported operand type(s) for -: 'NoneType' and 'float'' 我不知道它为什么会返回 NoneType 以及我该怎么做让减法工作?
self 和 p 都应该是对的。
def __init__(self, x, y):
self.x = float(x)
self.y = float(y)
def distToPoint(self,p):
self.ax = self.x - p.x
self.ay = self.y - p.y
self.ac = math.sqrt(pow(self.ax,2)+pow(self.ay,2))