I am trying to loop a while loop in a while loop, the total time it takes to execute, and write down the time it takes to do this, every time it loops. I need a way to achieve this using my code, if possible, or open up various concepts that I don't know about yet.
import random
import time
import sys
def main():
looperCPU = 500
start = time.time()
while (looperCPU != 0):
time.sleep(3)
random_number = random.randint(0,1000)
secondsPause = random.uniform(.75,4.75)
printerLooper = True
while printerLooper == True :
print("Sleeping for ", secondsPause, " seconds")
print(random_number)
printerLooper = False
print("total time taken this loop: ", time.time() - start)
looperCPU -= 1
main()
The loop will print the time, but I am very sure that it does not take into account the wait time of the nested loop. How can I let python use the time both in the loop and in each loop that it will need to do (in this case 500)?
source
share