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!") else: print("time is:",time.time().isoformat()," it's night time!") time = time + datetime.timedelta(0,1)
oops... the imports killed the simplicity :(
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
love the idea, but it doesn't run actually
Oh I was't expecting it to run, it meant to explain the idea of loops but here is one that works.
oops... the imports killed the simplicity :(