如何在python中暂停循环打印

时间:2015-10-18 03:29:06

标签: python loops while-loop pause

我有以下代码:

i = 0
numbers = []

while i < 6:
    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)

如果我导入sleep,它会降低速度,但我怎么能暂停它以便在我想要的时候继续进行?

1 个答案:

答案 0 :(得分:1)

只需将input()添加到您希望暂停的位置。

i=0
numbers = []
while i < 6:
    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)
    input() # add it here for example.


print("The numbers: ")

for num in numbers:
    print(num)