2015-10-18 58 views
0

一个循环打印我有以下代码:如何暂停在python

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会慢下来,但我怎么可以暂停,以便它进行时,我希望它?

+0

嗨。请注意我对你的问题所做的小副本编辑和格式。用代码片段开始问题并不好。你需要用问题本身来开始你的问题,或者至少要简单介绍一下。另外,您应该使用'<! - language:lang-python - >'注释来确保代码正确地被语法高亮显示。 (顺便说一句,欢迎来到StackOverflow。) – sideshowbarker

回答

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)