loading...

re: What is the simplest code to explain a loop? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: love the idea, but it doesn't run actually Traceback (most recent call last): File "python", line 1 time = 00:00:00 ^ SyntaxE...
 

Oh I was't expecting it to run, it meant to explain the idea of loops but here is one that works.

import datetime
time =datetime.datetime(100,1,1,0,0,0) # arbitrary day
sunIsSet = True
while (sunIsSet):
    if(time.hour > 5 and time.hour < 18):
       sunIsSet = False
       print("time is:",time.time().isoformat(), " it's day time!")
    else:
       print("time is:",time.time().isoformat()," it's night time!")
    time = time + datetime.timedelta(0,1)

oops... the imports killed the simplicity :(

code of conduct - report abuse