Python 3.x 如何在python中打印一定数量的数字字符
我正在做一个百分比查找器,非常基本。但是,我只想在float或int中打印4个字符。有人能帮忙吗? 以下是我目前的代码: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% 但它实际上打
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))
谢谢成功了!