Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 27, 2024. It is now read-only.

Commit 7ebae3c

Browse files
Merge pull request #142 from mintera10/alarm_clock
added my contribution ~
2 parents a4c3e4b + b00dca9 commit 7ebae3c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎Python/alarm_clock.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import datetime
2+
import time
3+
import pygame
4+
5+
def set_alarm(alarm_time):
6+
print(f"Alarm set for {alarm_time}")
7+
8+
while True:
9+
# Get the current time
10+
current_time = datetime.datetime.now().strftime("%H:%M:%S")
11+
print(f"Current Time: {current_time}", end="\r")
12+
13+
# Check if the current time matches the alarm time
14+
if current_time == alarm_time:
15+
print("\nWake up! It's time!")
16+
17+
# Initialize pygame mixer and play the alarm sound
18+
pygame.mixer.init()
19+
pygame.mixer.music.load('alarm_sound.mp3') # Make sure your alarm sound is in the same directory
20+
pygame.mixer.music.play()
21+
22+
# Wait for the music to finish
23+
while pygame.mixer.music.get_busy():
24+
time.sleep(1)
25+
26+
break
27+
28+
# Wait for 1 second before checking the time again
29+
time.sleep(1)
30+
31+
if __name__ == "__main__":
32+
# User input for the alarm time (HH:MM:SS format)
33+
alarm_time = input("Enter the alarm time (HH:MM:SS): ")
34+
set_alarm(alarm_time)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /