Created
July 8, 2020 07:44
-
-
Save Abhayparashar31/0c44a5da585a3b27ae4bbe9152d171df to your computer and use it in GitHub Desktop.
Create an alarm clock using python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from playsound import playsound | |
alarm_time = input("Enter the time of alarm to be set:HH:MM:SS\n") | |
alarm_hour=alarm_time[0:2] | |
alarm_minute=alarm_time[3:5] | |
alarm_seconds=alarm_time[6:8] | |
alarm_period = alarm_time[9:11].upper() | |
print("Setting up alarm..") | |
while True: | |
now = datetime.now() | |
current_hour = now.strftime("%I") | |
current_minute = now.strftime("%M") | |
current_seconds = now.strftime("%S") | |
current_period = now.strftime("%p") | |
if(alarm_period==current_period): | |
if(alarm_hour==current_hour): | |
if(alarm_minute==current_minute): | |
if(alarm_seconds==current_seconds): | |
print("Wake Up!") | |
playsound('audio.mp3') | |
break |
As a beginner i would like to know the meaning of this numbers: alarm_hour=alarm_time[0:2] alarm_minute=alarm_time[3:5] alarm_seconds=alarm_time[6:8]
@211991015 That is string slicing
we do this to extract specific parts of string
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As a beginner i would like to know the meaning of this numbers:
alarm_hour=alarm_time[0:2]
alarm_minute=alarm_time[3:5]
alarm_seconds=alarm_time[6:8]