top of page

A simple python alarm program

  • iudarath
  • May 24, 2021
  • 1 min read

Updated: Jun 28, 2021


Above is a simple python alarm program that works.

You can put any work to the print position and see it works with time.


The code is stated below also


import datetime


want_time =input("input the time you want to play alarm ")


play =True


print(want_time)


while play==True:

now=datetime.datetime.now()

timeparts=str(now).split(" ")

time_now= timeparts[1][0:5]

if want_time == time_now:

play=False

print (" you got the alarm")


Here is a another way of doing it.


This way it takes the time string of python. And split and takes the hour and minute part only.

But to both places now=datetime.datetime.now() function has to be taken dynamically. Inside a running while loop. That is the secret.


I'll put the code below to your inspection.


import datetime


play= True


want_time=input("input the time you want to play alarm ")


print(want_time)


while play==True:

now=datetime.datetime.now()

x= now.strftime("%X")

hourmin=x[0:5]

if want_time ==hourmin:

play=False

print (" you got the alarm")





 
 
 

Recent Posts

See All
අභිඤ්ඤාලාභී භික්ෂුණීන් අතර අග්‍ර වූ යශෝධරා මහ රහත් තෙරණිය-බුදුසරණ ඇසුරිනි

සුද්ධෝදන රජු බුදුරදුන් ළඟට ගොස් යශෝධරා කී දෙය දැන්වී ය. රජතුමනි යශෝධරාව බලන්න අපි යමු. සැරියුත් මුගලන් දෙනම ද බුදුරදුන් සමඟ වැඩියහ....

 
 
 

Comments


0719003300

  • Facebook
  • Twitter
  • LinkedIn

©2019 by udarath. Proudly created with Wix.com

bottom of page