+的操作数类型不受支持:“int”和“classobj”

2024-04-27 02:34:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着从两条直线的交点处找到坐标,在相交定义处,我有一个错误:

unsupported operand type(s) for +: 'int' and 'classobj' 

我能做些什么来修复它?在

^{pr2}$

Tags: andfor定义type错误直线int交点
2条回答

改变

Line2=IntersectionPoint(3,-1 -1, Line1)

^{pr2}$

您传入了4个参数,但缺少一个逗号

您正在将一个类对象传递给IntersectionPoint()

Line2=IntersectionPoint(3,-1 -1, Line1)

Line1是一个类。这是函数的第三个参数,因为这两个-1参数之间没有逗号。因此,您将3分配给a2-2分配给b2,并将{}分配给c2。在

然后,在intersect方法中,将该类对象添加到一个整数中:

^{pr2}$

其中self.c2是您的Line1类。在

你想要:

Line2 = IntersectionPoint(3, -1, -1)

相反。在

下一个错误是:

return 'True. The intersection point is: I' (xcord,ycord) 

因为这就像是把字符串当作函数。您可能缺少字符串格式操作,或者缺少逗号:

return 'True. The intersection point is: (%d, %d)' % (xcord,ycord) 

或者

return 'True. The intersection point is: I', (xcord,ycord) 

相关问题 更多 >