第三第四题,这是Python程序设计的题目,
发布网友
发布时间:2022-05-11 06:27
我来回答
共1个回答
热心网友
时间:2024-03-11 13:18
# -*- coding: utf-8 -*-
import math
OnePoint = (1,2)
TwoPoint = (-2,-6)
print math.sqrt((OnePoint[0]- TwoPoint[0]) * (OnePoint[0]- TwoPoint[0]) + (OnePoint[1]- TwoPoint[1]) * (OnePoint[1]- TwoPoint[1]))
# -*- coding: utf-8 -*-
import math
def fun(OnePoint, TwoPoint):
k = (TwoPoint[1] - TwoPoint[0])/float(OnePoint[1] - OnePoint[0])
b = TwoPoint[1] - k * OnePoint[1]
return k ,b
def fun1(ThreePoint):
k ,b = fun(OnePoint, TwoPoint)
fenmu = math.sqrt(1+k*k)
fenzi = math.fabs(ThreePoint[1] - k*ThreePoint[0])
return fenzi/fenmu
if __name__ == "__main__":
OnePoint = (1,2)
TwoPoint = (-2,-6)
ThreePoint = (8,12)
value = fun1(ThreePoint)
print value