【发布时间】:2014-04-14 02:12:53
【问题描述】:
我不明白为什么当 totalArea 的 'start' 参数为 0 时,下面的代码会陷入无限循环。我一直在看 Python Tutor 中运行的代码,并且 j 通过 Stop -1 的值执行,但是然后重置为 0 而不会移动到 Stop 的值。
import math
def totalArea(start, stop, step):
def f(x):
return 10*math.e**(math.log(0.5)/5.27 * x)
area = 0.0
j = start
while j <= len(range(start, stop)):
for j in range(start, stop):
area += float(step) * f(j)
print area
totalArea(0, 11, 1)
【问题讨论】:
标签: python while-loop infinite-loop