38讲点和直线的距离
import mathclass Point:
def __init__(self,x,y):
self.x =x
self.y=y
def getX(self):
returnself.x
def getY(self):
return self.y
class Line:
def __init__(self,p1,p2):
self.x =p1.getX() -p2.getX()
self.y = p1.getY()-p2.getY()
self.line = math.sqrt(math.pow(self.x,2))+math.pow(self.y,2)
def getLen(self):
return self.line
x1,y1 = input("点x1和y1是:")
p1 = Point(x1,y1)
x2,y2 = input("点x2和y2是:")
p2 = Point(x2,y2)
line = Line(p1, p2)
line.getLen()
ValueError: too many values to unpack (expected 2)为什么会出错 因为你只给了一个值,不能偷懒,
要分开写。 本帖最后由 wuqramy 于 2020-4-20 15:02 编辑
可能是输入的时候只传入了一个参数,还是要分别输入每个点的位置 {:10_277:} 最后那一段改成这样x1 = y1 = input("点x1和y1是:")
p1 = Point(x1,y1)
x2 = y2 = input("点x2和y2是:")
p2 = Point(x2,y2)
line = Line(p1, p2)
line.getLen()
页:
[1]