checkily 发表于 2018-2-24 16:51:42

39课练习,求两点之间的距离

import math

class Point:
   
    def setPoint(self):
      self.x=int(input('输入X的坐标:'))
      self.y=int(input('输入Y的坐标:'))

      return self.x,self.y

class Line(Point):

    def getLen(self):      
      length=math.sqrt((p_A.x-p_B.x)**2+(p_A.y-p_B.y)**2)
      print('点A(%d,%d)到点B(%d,%d)的距离是:%.2f' % (p_A.x,p_A.y,p_B.x,p_B.y,length))
      
print('输入A点的坐标:')
p_A=Point()
p_A.setPoint()

print('输入B点的坐标:')
p_B=Point()
p_B.setPoint()

line=Line()
line.getLen()
页: [1]
查看完整版本: 39课练习,求两点之间的距离