函数内部的Python无限while循环

2024-04-26 21:03:18 发布

您现在位置:Python中文网/ 问答频道 /正文

无论我尝试什么,我都会用这个函数得到一个无限循环:

  # Excercise 33 - LPTHW

i = 0 
numbers = []

#Ec 1
#numb = 6
#iplus = 10

def theloop(numb):
        global i
        #i = 0
        #number = []
        while i < numb:
            print "At the top of i is %d" % i
            numbers.append(i)

            i = i + 1
            print "Numbers now: ", numbers
            print "At the bottom i is %d" % i

        print "The numbers: "

        for num in numbers:
            print num

theloop(7)

当我运行脚本时,它会一直打印:

At the top of i is 0
At the top of i is 0
...

提前谢谢。


Tags: ofthe函数istopplusnumat