# -*- coding:utf-8 -*- """ @author: 14931 @file: trianglearea.py @time: 2023/02/14 @desc: """ import math #导入模块 class Point: #创建类,得到一个点 def __init__(self,a=0,b=0): self.a = a self.b = b def getA(self): return self.a def getB(self): return self.b class Line: #计算两个点的距离 def __init__(self,p1,p2): self.a = p1.getA() - p2.getA() self.b = p1.getB() - p2.getB() self.len = math.sqrt(self.a*self.a + self.b*self.b) def getlen(self): return self.len p1 = Point(1,2) p2 = Point(4,6) lineLen = Line(p1,p2) print(lineLen.getlen())
标签:p2,__,p1,python,getA,self,距离,坐标,def From: https://www.cnblogs.com/shirleysu90/p/17120135.html