import time
while True:
start=time.time()
time.sleep(2)
end=time.time()
howlong = end - start
print(howlong)
I coded this so that I can have something happen 2 seconds later. the expected output is 2.00 yet the output varies between 2.00 and 2.02 on my pc. is there anything I can do so that I always have less than 2.01 every time? I haven’t tried anything since I’m a noob.
Edit: Never mind I switched to this:
while True:
start = time.time()
goal = start+2
while True:
end = time.time()
if end >= goal:
print(end-start)
break
The results are more consistent.