I am trying to make a timer that after 10 seconds prints a string .
I tried to use time.sleep()
and it did not work.
Example:
def tempo():
#passados 10 segundos
print "olá"
I am trying to make a timer that after 10 seconds prints a string .
I tried to use time.sleep()
and it did not work.
Example:
def tempo():
#passados 10 segundos
print "olá"
Use the time.sleep()
method.
import time
def tempo():
time.sleep(10)
print "Ola"
To make a stopwatch and print the number on the same line:
import time, sys
for i in range(0, 10):
sys.stdout.write("\r{}".format(i))
sys.stdout.flush()
time.sleep(1)
print ("\nFim")
I think a smaller form would be:
from time import sleep
for contagem in range(0,10):
sleep(1)
print('Olá!')