【发布时间】:2018-12-28 05:48:09
【问题描述】:
所以这是代码,它会永远持续下去,但我无法追踪原因。在某些时候我应该是 10,然后 10
i = 0
numbers = []
abc = range(0, 10)
def loop(i):
while i < abc:
print 'at the top i is %d' % i
numbers.append(i)
i = i + 1
print 'NUmbers now: ', numbers
print 'at the bottom i is %d' %i
quest = raw_input('> ')
if quest == 'i':
loop(i)
print "the numbers: "
for num in numbers:
print num
【问题讨论】:
-
您将
int与list进行比较?而list在 Python 2 中总是大于intstackoverflow.com/questions/7167657/… -
这可以帮助你在下一轮解决这样的奇迹:How to debug small programs (#1)
标签: python python-2.7 while-loop infinite-loop