试写一个python程序,求平面直角坐标系中两点的距离:
class Coordinate: def __init__(self,x,y): self.x=x self.y=y def distance(self,other): x_diff_sq=(self.x-other.x)**2 print(x_diff_sq) y_diff_sq=(self.y-other.y)**2 print(y_diff_sq) return (x_diff_sq+y_diff_sq)**0.5 a=Coordinate(1,2) b=Coordinate(4,6) D=a.distance(b) print('a和b之间的距离是:',D) 输出: 9 16 a和b之间的距离是: 5.0求平面两点之间的距离
标签:记录,sq,Coordinate,算法,other,print,diff,self From: https://www.cnblogs.com/xiaoxiamiaichiyu/p/18019257