|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 指尖、行 于 2017-7-12 21:38 编辑
以下这段代码运行后出现 TypeError: 'float' object is not callable
求助
import math as m
import random as r
class Point:
def __init__(self):
self.x = r.randint(0, 100)
self.y = r.randint(0, 100)
print('该点的x坐标为:%d\n该点的y坐标为:%d' % (self.x, self.y))
def self_x(self):
return self.x
def self_y(self):
return self.y
class Line:
def __init__(self, PointA, PointB):
# PointA = Point()
# PointB = Point()
self.line_x = PointA.self_x() - PointB.self_x()
self.line_y = PointA.self_y() - PointB.self_y()
self.length = m.sqrt(self.line_x *self.line_x + self.line_y*self.line_y)
def length(self):
return self.length
变量名跟方法名冲突了,如下修改即可:
- import math as m
- import random as r
- class Point:
- def __init__(self):
- self.x = r.randint(0, 100)
- self.y = r.randint(0, 100)
- print('该点的x坐标为:%d\n该点的y坐标为:%d' % (self.x, self.y))
- def self_x(self):
- return self.x
-
- def self_y(self):
- return self.y
- class Line:
- def __init__(self):
- PointA = Point()
- PointB = Point()
- self.line_x = PointA.self_x() - PointB.self_x()
- self.line_y = PointA.self_y() - PointB.self_y()
- self.length = m.sqrt(self.line_x *self.line_x + self.line_y*self.line_y)
- def getLength(self):
- return self.length
复制代码
|
|