两点距离的编程
#求两点距离
import math
class Point:
def move(self,x,y):
self.x = x
self.y = y
def reset(self):
self.move(0,0)
#计算两点距离
def calculate_distance(self,other_point):
return math.sqrt(
(self.x-other_point.x)**2+
(self.y-other_point.y)**2)
#使用
point1=Point()
point2=Point()
#调用点1的方法
#调用点2的方法,让x=5
point1.reset()
point2.move(5,0)
#计算点2到点1的距离,输出
print(point2.calculate_distance(point1))
#移动点1到x=3,y=4新位置
point1.move(3,4)
#计算点1和点2的距离
print(point1.calculate_distance(point2))