小编ink*_*ay_的帖子

为什么这是一个无限循环

a = raw_input ("enter a number")
i = 0
numbers = []

while i < a:
    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

print "The numbers: "

for num in numbers:
    print num   
Run Code Online (Sandbox Code Playgroud)

所以我正在关注lpthw并且只是搞乱了代码,为什么当我使用raw_input并输入一个像6这样的数字时这个循环会变成无限循环?不应该i = i + 1在那里阻止这种情况发生吗?

python python-2.7

1
推荐指数
1
解决办法
148
查看次数

标签 统计

python ×1

python-2.7 ×1