I am trying to execute a block of code when it is past a certain time. However, when the program executes, the current_time
variable saves the time the program started, and does not keep time while the program is running.
The only thing I found that could be a possible solution to that problem is putting current_time
on a while
loop so the time updates while the program is running, but this is shown to crash the program. How to do this while not crashing the program?
<code>import time
import sys
start_time = "07:00:00"
break_time = "10:00:00"
current_time = time.strftime("%H:%M:%S")
while current_time > start_time and current_time < break_time:
current_time = time.strftime("%H:%M:%S") # loop crashes the program
print(current_time)
if current_time < start_time or current_time > break_time:
print("The program will now be terminated.")
sys.exit()
</code>
<code>import time
import sys
start_time = "07:00:00"
break_time = "10:00:00"
current_time = time.strftime("%H:%M:%S")
while current_time > start_time and current_time < break_time:
current_time = time.strftime("%H:%M:%S") # loop crashes the program
print(current_time)
if current_time < start_time or current_time > break_time:
print("The program will now be terminated.")
sys.exit()
</code>
import time
import sys
start_time = "07:00:00"
break_time = "10:00:00"
current_time = time.strftime("%H:%M:%S")
while current_time > start_time and current_time < break_time:
current_time = time.strftime("%H:%M:%S") # loop crashes the program
print(current_time)
if current_time < start_time or current_time > break_time:
print("The program will now be terminated.")
sys.exit()