如何在 python 中暂停循环打印
How to pause a loop print in 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
它会减慢它的速度,但是我怎样才能暂停它以便它在我想要的时候继续?
只需在您希望它暂停的地方添加 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)
我有以下代码:
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
它会减慢它的速度,但是我怎样才能暂停它以便它在我想要的时候继续?
只需在您希望它暂停的地方添加 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)