该数字的第二个根最多可达4位小数

时间:2018-05-13 08:00:09

标签: python python-3.x

我打算打印用户打算在输出中打印最多4个小数位的第四个数字位 如何在不使用Round()函数的情况下获得最多四位小数?

import math 
n = int(input('Do you want to calculate the root of a few numbers? --> '))

for i in range(n):
    usrinp = int(input('Enter the number for root --> '))
    x = math.sqrt(usrinp)

    print(x)

例如:

你想计算几个数字的根吗? - > 4

输入root的数字 - > 1

输入root的数字 - > 2

输入root的数字 - > 3

输入root的数字 - > 19

输出:

1.0000

1.4142

1.7320

4.3588

1 个答案:

答案 0 :(得分:0)

要获得没有round功能的4位小数:

print('{:0.4f}'.format(x))