+ 1
How to stop "while True" in this code after 1 hour
import time while True: def fivetozero(): i = 1 while i <= 5: print(i) i = i + 1 time.sleep(2) #loop every2s print("finished") fivetozero() it goes forever... how to make a stop time for this code or in other words.. make fivetozero() func stop
4 Respuestas
+ 5
use datetime and check difference
https://code.sololearn.com/ctLRoch8abdi/?ref=app
+ 2
Worked! with some little modifications
+ 1
count=0;
while count<1800:
def fivetozero():
i = 1
while i <= 5:
print(i)
i = i + 1
IF(time.sleep(2)) count++ #loop every2s
print("finished")
fivetozero()
+ 1
Nice! kheili khub!