2015-10-18 66 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)