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'.
Rik Poggi
29.5k7 gold badges69 silver badges84 bronze badges
asked Jan 14, 2012 at 17:34
Bruno 'Shady'
4,56615 gold badges58 silver badges75 bronze badges
-
1Why os not working? There is an error? And what exactly should your program do?Rik Poggi– Rik Poggi2012年01月14日 17:54:27 +00:00Commented Jan 14, 2012 at 17:54
-
I agree with Rik. You should make it a habit to include the traceback in your question.Joel Cornett– Joel Cornett2012年01月14日 22:36:42 +00:00Commented Jan 14, 2012 at 22:36
1 Answer 1
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
answered Jan 14, 2012 at 18:04
ekhumoro
122k23 gold badges272 silver badges400 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py