【发布时间】:2014-01-04 14:51:33
【问题描述】:
这是教程的一部分。我的目标是从用户那里获取输入,然后在条件为真时增加它。
inputNum = raw_input("What is max number?")
def incrementF(greatest):
i = 0
numbers = []
while i < greatest:
print "At the top of the list numbers is %d" % i
numbers.append(i)
i += 1
print "Numbers now: ", numbers
print "At the bottom i is %d" % i
print "The numbers:"
for num in numbers:
print num
incrementF(inputNum)
当我运行脚本并为 inputNum 输入任何内容而不是几行输出时,我似乎陷入了无限循环。
例如,原始输入提示是否给出了 10,我希望看到类似的内容:
At the top of the list numbers is 0, Numbers now: 0, 0 At the top of the list numbers is 1, Numbers now: 1, 1
我已经多次阅读我的脚本,但看不到。我怀疑这可能与缩进有关?但我不确定。
【问题讨论】:
标签: python while-loop infinite-loop python-2.x