嗨,我是 python 的新手,我很难理解这个简单的 while 循环。这个程序应该计算细菌加倍所需的时间。
time = 0
population = 1000 # 1000 bacteria to start with
growth_rate = 0.21 # 21% growth per minute
while population < 2000:
population = population + growth_rate * population
print population
time = time + 1
print "It took %d minutes for the bacteria to double." % time
print "...and the final population was %6.2f bacteria." % population
结果是:
1210.0
1464.1
1771.561
2143.58881
It took 4 minutes for the bacteria to double.
...and the final population was 2143.59 bacteria.
我不明白的是为什么最终结果大于 2000 导致它应该在 2000 年之前停止。我有什么问题吗?