我有一个简单的 python 程序
除法后,它显示最终值,但我不想显示 .01
from __future__ import division
number = int(133)
output = float(0)
divideNumber = int(1)
stop = false
while stop == false
halfNumber = number / 2
output = number / divideNumber
output = round(output, 2)
if ".0" in str(output):
if "0.1" in str(output) or "0.2" in str(output ) or.... "0.9" in str(output):
#Do Nothing
else:
#Do Nothing
else:
print str(number) + " / " + divideNumber + " = "str(output)
divideNumber += 1
if divideNumber < halfNumber:
break
else:
#Do Nothing
print "Goodbye"
如果我运行它,结果如下:
133 / 1 = 133.0
133 / 7 = 19.0
133 / 11 = 12.09
133 / 12 = 11.08
133 / 19 = 7.0
133 / 22 = 6.05
133 / 33 = 4.03
133 / 43 = 3.09
133 / 44 = 3.02
133 / 64 = 2.08
133 / 65 = 2.05
133 / 66 = 2.02
再见
我的预期结果是
133 / 1 = 133.0
133 / 7 = 19.0
133 / 19 = 7.0
Goodbye
我的“if”语句错了吗?我没有收到任何错误!