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

time = 00:00:00
SunIsSet = true
while (sunIsSet):
    print("it's night time!")
    time += 1
    if(time > 05:00:00 < 18:30:00):
       SunIsSet =false
       print("it's day time!")

love the idea, but it doesn't run actually

Traceback (most recent call last):
  File "python", line 1
    time = 00:00:00
SyntaxError: invalid syntax

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!")
       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