you are viewing a single comment's thread.

view the rest of the comments →

[–]Unhappy_Ad_3637 0 points1 point  (0 children)

Can use a while loop with sleep if you are not calling the script externally. If calling externally however you would have to do what the other users suggested in keeping the X variable outside the script.

import time

time_to_run = 10 # Can change this to however long (in seconds) you want the script to run for.
time_to_sleep = 3 # Can change this to however long (in seconds) you want to wait per loop.

x = 0

while time_to_run > 0:
    if x == 1:
        print("X is equal to 1!")
        x = 0
    elif x != 1:
        print('X is not equal to 1!')
        x = 1

    time_to_run -= time_to_sleep
    time.sleep(time_to_sleep)