当给定输入时,我得到的结果是1.0,但我需要它是1.00000000000我应该如何在hyp中修改??
small=1000000000
from math import hypot
def pairwise(iterable):
a, b = iter(iterable), iter(iterable)
next(b, None)
return zip(a, b)
n=int(input())
l1=[]
l2=[]
for i in range(0,n):
c,d=list(map(int,input().split()))
l1.append(c)
l2.append(d)
a=tuple(l1)
b=tuple(l2)
dist = [float(hypot(p2[0]-p1[0], p2[1]-p1[1])) for p1, p2 in pairwise(tuple(zip(a, b)))]
for x in dist:
if x<small:
small=x
print(small)
您可以像这样使用format
方法:
format(math.pi, '.12g') # Give 12 significant digits of pi
format(math.pi, '.2f') # Give 2 digits of pi after decimal point
您可以将打印更改为
print(f'{small:.12f}')