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



Comments