I am trying to run two while loops based on an input condition. In this example, that is taken out and replaced by a 1 == 0 so that 0 can be changed back and forth for testing. Once selected, each while loop should run for 10 seconds and then the input condition checked (replaced by 1 == 0) again.
The problem appears to be in the time comparison, since it never evaluates correctly. What am I missing?
#!/usr/bin/env python3
import time
import os
import bellmod
while True:
starttime = time.time()
print("Start time " + str(starttime)) #Time check
elapsedtime = 0 #Reset elasped time to 0 for each loop iteration.
if 1 == 0: #Change this to run either loop. See if remote or local has precidence.
while(elapsedtime < 10):
print("Inside remote while " + time.strftime("%H:%M:%S")) #Time check
elapsedtime = time.time() - starttime #Calculate elasped time.
else:
elapsedtime = 0
while(elapsedtime < 10):
print("inside bottom of local while " + str(int(time.time() - starttime))) #Time check
elapsedtime = time.time() - starttime #Calculate elasped time.
time.sleep(10)to wait ten seconds?elapsedtimeis updated?