python - python中的十进制表示
问题描述
当给定输入时,我得到像 1.0 这样的结果,但我需要它是 1.000000000000 我应该如何在hypot中修改?
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
推荐阅读
- android - IntelliJ IDEA Ultimate control + alt + L 和 Android XML 布局顺序
- yaml - 是否可以根据 Jekyll 中的前沿变量对项目进行分组?
- android - Android Gradle 插件 3.4.0 之后的日志语句(带有 R8 编译器)
- html - POST 请求的 HTML 表单下载响应
- batch-processing - Keras 和循环神经网络:单变量数据批次的输入是什么样的
- c# - 仅在发生更改时如何从更新中调用 ShootingSettings 方法?
- apache-spark - IF 语句可以正常工作以构建 spark 数据框吗?
- java - Jersey 忽略自定义 ObjectMapper
- php - 你推荐什么 docker 的镜像用于生产,php 或 php-alpine?
- css - 我做错了什么?“响应页面”