Reputation: 4516
I have the following code:
s = ['01','06','11','16','21','26','31','36','41','46','51','56']
while True:
for a in s:
if time.strftime('%S') == a:
print 'YES'
else:
print time.strftime('%S')
time.sleep(1)
print a
And it doesn't work.
Any ideas how to make it work?
In case, everytime the %S
gets some of the value in s
, it prints the 'YES'
.
Upvotes: 0
Views: 101
Reputation: 120608
You need to call sleep
on every loop and look for the current seconds in your list of matches:
>>> import time
>>>
>>> matches = ['01','06','11','16','21','26','31','36','41','46','51','56']
>>>
>>> while True:
... seconds = time.strftime('%S')
... if seconds in matches:
... print('YES')
... else:
... print(seconds)
... time.sleep(1)
...
07
08
09
10
YES
12
13
14
15
YES
17
18
19
Upvotes: 2