+ 1
Repeat while loop
How to repeat a while loop scope infinit time for an amount of time. for example loop through 5 to 0 for 1 hour. over and over again
4 Respuestas
+ 11
So, what you're basically asking is how to have a process executed for a specific amount of time?
+ 4
This version runs for a second, change x to 3600 if you want it to run for an hour:
import time
# use x = 3600 if you want to run it for an hour, it may overheat your computer
x = 1 # make it run for x seconds
y = time.time() + x
z = time.time()
while z < y:
z = time.time()
for u in range(5, -1, -1):
print(u, end = ' ')
print ("")
+ 3
This will run until the end of the hour (Or time limit exceded):
import time
y = int(time.strftime("%H"))
x = y
while y == x:
y = int(time.strftime("%H"))
print(y)
I got time limit exceeded.
+ 1
Let me ask
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