|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
动动手0:我不知道理解的对不对。
# 定义一个点Spot类,和一个直线Strline类,使用getLen方法可以获得直线的距离。
- import math as m
- class Spot():
- def __init__(self):
- Ax = float(input("请输入Ax:"))
- Ay = float(input("请输入Ay:"))
- Bx = float(input("请输入Bx:"))
- By = float(input("请输入By:"))
- self.Ax = Ax
- self.Ay = Ay
- self.Bx = Bx
- self.By = By
- class Strline(Spot):
- def __init__(self):
- Spot.__init__(self)
- def getLine(self):
- self.x_diff = self.Ax - self.Bx
- self.y_diff = self.Ay - self.By
- self.distance = m.sqrt(self.x_diff ** 2 + self.y_diff ** 2)
- print("A点的坐标是:", (self.Ax, self.Bx))
- print("B点的坐标是:", (self.Bx, self.By))
- print("A点与B点之间的距离是%.3f:" % self.distance)
- coordinate = Strline()
- coordinate.getLine()
复制代码 |
|