Skip to content
Sign upLog in
← Back to Community

Time

Profile icon
ObiWan152

How do I add time? I mean like for my codeing I want it to wait like 5 sec before it continues.Can yall help me out

Answered by RYANTADIPARTHI [earned 5 cycles]
View Answer
Voters
Profile icon
ObiWan152
Comments
hotnewtop
Profile icon
RYANTADIPARTHI

You have to use time.sleep() to do this job:

import time print('Hi') time.sleep(5) # change the number to how many seconds you want print('this is 5 seconds later')

like that.
That should work

Profile icon
FlaminHotValdez

There is a sleep function in the time module. The code would be

import time
time.sleep(amount of seconds to sleep)

Profile icon
Coder100

What you are looking for is time.sleep.

import time print("Hello, ") time.sleep(5) print("World!")

read more

Profile icon
Bookie0

For python, you can import the module time:

import time # importing time print("Hi!") time.sleep(1) # program waits 1 second print("And I'm back after 1 second!")

You can also do this:

from time import sleep # imports sleep from time print("Hi!") sleep(1) # program waits 1 second print("And I'm back after 1 second!")

The only difference is that on the first line we do from time import sleep and when we want to use it, we do sleep(seconds) instead of time.sleep(seconds). It's the same thing.

:)

Profile icon
littlepenguin
import time # Waits 5 secs time.sleep(5)