manev
manev

Reputation: 63

Python if condition after amount of time

I have a basic code with simple condition:

if var1 > 0 :   
   dosomething

how can I prolong the execution after the condition is true for few seconds? Something like:

if var > 0 ("after 5 seconds"):
   dosomething

Upvotes: 0

Views: 45

Answers (2)

Taufiq Rahman
Taufiq Rahman

Reputation: 5714

Try something like this ; sleep(5) will delay the program for 5 seconds:

import time 

x = 10
if x > 0:
    # if true 
    time.sleep(5)
else:
     #dosomething

Upvotes: 0

user1781434
user1781434

Reputation:

Use time.sleep at an appropriate place:

from time import sleep
sleep(5)  # will block for 5 seconds

Upvotes: 3

Related Questions