0

I have a query for a small program that I am running. I was wondering if there was any way to pause a while loop in python for an amount of time? Say for example if I wanted it to print something out, then pause for say (1) second, then print it out again?

There is not really a point to this program I am more doing it for something to do while bored. I have checked other questions and none seemed to really answer what I was asking.

steamidge_
  • 17
  • 1
  • 3
  • 7

2 Answers2

0
import time
while ...
    print your line
    time.sleep(1) # sleep for one second

time sleep method

Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
0

Yes. There is a function called sleep that does exactly what you want:

while true:
  print "Hello!\n"
  time.sleep(1)
Linuxios
  • 34,849
  • 13
  • 91
  • 116