python测试ch08

代码

import random
num1=random.randrange(1,10)
num2=random.randrange(1,10)
class PointLenth:
    def __init__(self,x1,y1,x2,y2):
        self.x1=x1
        self.x2=x2
        self.y1=y1
        self.y2=y2
    def lenth(self):
        dx=(self.x1)-(self.x2)
        dy=(self.y1)-(self.y2)
        distance=(dx**2+dy**2)**0.5
        print(distance)

p1=PointLenth(num1,17,num2,7)
print(p1.lenth())

运行结果

posted on 2021-12-03 22:51  20211417黄琪凯  阅读(38)  评论(0编辑  收藏  举报