I'm trying to return the answer of the code below into a variable, the variable should change every 5 seconds therefore I can't use 'return' since it ends the function.
example:
from time import sleep
def printit():
cpt = 1
while True:
if cpt < 3:
number = ("images[" + str(cpt) + "].jpg")
return number #here is the return
sleep(5)
cpt+=1
else:
printit()
answer = printit()
print(answer) #only 1 answer is printed, then the function ends because of the 'return'
What is the solution to resolve this problem?
The variable answer should change every 5 seconds without ending the function.