Icc
Icc

Reputation: 3

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?

Upvotes: 0

Views: 650

Answers (1)

Leb
Leb

Reputation: 15953

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)

Upvotes: 1

Related Questions