我现在正在尝试自学Python,使用“Learn Python The Hard Way”中的练习。
目前,我正在做一个关于while循环的练习,其中我要从脚本中获取一个有效的while循环,将其转换为函数,然后在另一个脚本中调用该函数。最终程序的唯一目的是将项目添加到列表中,并在进行时打印列表。
我的问题是,一旦调用函数,嵌入式循环就会无限继续。
我已经多次分析了我的代码(如下所示),但没有发现明显的错误。
def append_numbers(counter):
i = 0
numbers = []
while i < counter:
print "At the top i is %d" % i
numbers.append(i)
i += 1
print "Numbers now: ", numbers
print "At the bottom i is %d" % i
count = raw_input("Enter number of cycles: ")
print count
raw_input()
append_numbers(count)
raw_input
关键字。 - Joel Cornettraw_input
并通过此脚本以更高的特权执行它。换句话说,您提供了一个可怕的解决方案,任何注重安全的程序员都知道应该避免。 - Susam Pal