0

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
2
  • 1
    Why os not working? There is an error? And what exactly should your program do? Commented Jan 14, 2012 at 17:54
  • I agree with Rik. You should make it a habit to include the traceback in your question. Commented Jan 14, 2012 at 22:36

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.