简体   繁体   中英

How to pause a loop print in python

I have the following code:

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)

If I import sleep it will slow it down, but how can I pause it so it proceeds when I want it to?

Just add input() where you want it to 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)
    input() # add it here for example.


print("The numbers: ")

for num in numbers:
    print(num)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM