Introduction of Program
Today I am going to discuss another python program. Here you will find "How to Create an Alarm System Using Python?". We have the facility to set Alarm in our phone. We can also program an alarm with the help of python. It can also program an alarm with the same or more features as the alarm of the mobile phone and we can customize it later. I am trying to advance this program a little bit, for example- I have kept the option of data/history file in this Alarm System. By this, the message given along with the time of your alarm will be stored in a file. Here you have to work as a message. You can give his details so that if you forget later when the alarm goes off, you will remember what it you set the alarm for. To understand what formula or logic we will use in this program, it will be written by commenting next to the main codes.
You can get the complete source code and output player of this program in this blog. I will create this program using Pycharm editor as usual. However, you can make it using any other Py editor (like- VS Code), the code will be all the same. I used python 3.9.7 when doing this program.
If you are a python beginner or if you are looking for a practice problem like python then you can go to the home page of this website and visit all the posts. I hope you like this post.
My Website: Rajtech99 only technology
My Quora Space: Rajtech99
Alarm System Programming
Alarm System |
Source Code:
# All imported modulus
from time import time
from pygame import mixer
# Main Body
while True:
print("Welcome to RajTech99 only Technology\n")
inp = int(input("Enter '1' for Start program\nEnter '0' for Exit Program\n"))
if inp == 1:
print("Enter time in terms of Day:Hr:Min:Sec\n")
time1 = time()
msg = input("Enter your Message: \n")
Day = int(input("Enter time in Day. Enter Here: \n"))
Hr = int(input("Enter time in Hr. Enter Here: \n"))
Min = int(input("Enter time in Min. Enter Here: \n"))
Sec = int(input("Enter time in Sec. Enter Here: \n"))
print(f"Your Entered Time: {Day}D:{Hr}H:{Min}M:{Sec}S\n")
var = int(Day*24*60*60 + Hr*60*60 + Min*60 + Sec)
init_alarm = time()
alarm_time = var
def alarm_sound(file, stopper):
mixer.init()
mixer.music.load(file)
mixer.music.play()
while True:
a = input("Enter 'stop' to stop the alarm sound\n")
if a == stopper:
print(f"Good Day!!\n")
mixer.music.stop()
break
else:
print("Your Input is wrong!!try again\n")
continue
while True:
if time()-init_alarm > alarm_time:
alarm_sound('Phone Alerts And Rings.mp3.mp3', "stop")
with open("Alarm.txt", "a") as f:
f.write(f"{msg}: {time1}\n")
break
elif inp == 0:
print("Exit!!")
break
else:
print("Your Input is wrong.try again\n")
continue