python平面上的两点间距离计算?

Python026

python平面上的两点间距离计算?,第1张

直接用勾股定理。

x1,y1=map(int,input().split(','))

x2,y2=map(int,input().split(','))

print('{:.2f}'.format((x1-x2)**2+(y1-y2)**2)**0.5))

import math

class Dot:

     def __init__(self,x,y,z):

          self.x=float(x)

          self.y=float(y)

          self.z=float(z)   

t1=input('请输入点t1的坐标:')

t2=input('请输入点t2的坐标:')

t1=eval('[%s]'%t1)

t2=eval('[%s]'%t2)

T1=Dot(t1[0],t1[1],t1[2])

T2=Dot(t2[0],t2[1],t2[2])

print('点t1:',T1.x,T1.y,T1.z)

print('点t2:',T2.x,T2.y,T2.z)

s=math.sqrt((T1.x-T2.x)*(T1.x-T2.x)-(T1.y-T2.y)*(T1.y-T2.y)+(T1.z-T2.z)*(T1.z-T2.z))

print("两点间的距离为:%s"% s)