+ 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

14th Aug 2018, 1:08 PM
Iman Rafi
Iman Rafi - avatar
4 Respuestas
+ 5
use datetime and check difference https://code.sololearn.com/ctLRoch8abdi/?ref=app
14th Aug 2018, 2:39 PM
Oma Falk
Oma Falk - avatar
+ 2
Worked! with some little modifications
14th Aug 2018, 2:24 PM
Iman Rafi
Iman Rafi - avatar
+ 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()
14th Aug 2018, 1:20 PM
MarJan
MarJan - avatar
+ 1
Nice! kheili khub!
14th Aug 2018, 1:23 PM
Iman Rafi
Iman Rafi - avatar