Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在python中打印一定数量的数字字符_Python 3.x - Fatal编程技术网

Python 3.x 如何在python中打印一定数量的数字字符

Python 3.x 如何在python中打印一定数量的数字字符,python-3.x,Python 3.x,我正在做一个百分比查找器,非常基本。但是,我只想在float或int中打印4个字符。有人能帮忙吗? 以下是我目前的代码: numer = int(input("What's the numerator?")) denom = int(input("What's the denominator?")) percent = (numer / denom * 100, "%") print(percent) 我希望5/6的输出为: 83.33% 但它实际上打

我正在做一个百分比查找器,非常基本。但是,我只想在float或int中打印4个字符。有人能帮忙吗? 以下是我目前的代码:

    numer = int(input("What's the numerator?"))
    denom = int(input("What's the denominator?"))
    percent = (numer / denom * 100, "%")
    print(percent)
我希望5/6的输出为:

    83.33%
但它实际上打印:

    83.33333333333334%

您可以在打印功能中使用%

print("%.2f"%(a/b))

谢谢成功了!