File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ from playsound import playsound
2
+ # function that allows us to play the sound by simply calling playsound("the-name-of-the-sound.mp3")
3
+ import time
4
+
5
+ CLEAR = "\033 [2J" # clears entire terminal (the program will then print the statement at the bottom of the alarm function)
6
+ CLEAR_AND_RETURN = "\033 [H" # then this will clear the terminal and return the function again, printing over the previous function output
7
+
8
+ def alarm (seconds ):
9
+ time_elapsed = 0
10
+
11
+ print (CLEAR )
12
+ while time_elapsed < seconds :
13
+ time .sleep (1 ) # makes the program wait for 1 second. without it the program will run as fast as the computer can run it
14
+ time_elapsed += 1 # adds 1 second after every loop
15
+
16
+ time_left = seconds - time_elapsed
17
+ minutes_left = time_left // 60 # indeger division(e.g: 125 // 60 = 2 because 60 evenly divides 125 two times)
18
+ seconds_left = time_left % 60 # the remainder after division (e.g: 125 % 6 = 5)
19
+
20
+ print (f"{ CLEAR_AND_RETURN } Alarm will sound in: { minutes_left :02d} :{ seconds_left :02d} " )
21
+ # :02d = make this number a 2 digits number and add a leading 0 if it's not 2 digits already
22
+
23
+ playsound ("alarm-sound.mp3" )
24
+
25
+ minutes = int (input ("How many minutes to wait: " ))
26
+ seconds = int (input ("How many seconds to wait: " ))
27
+ total_seconds = minutes * 60 + seconds
28
+ alarm (total_seconds )
29
+
30
+
31
+
You can’t perform that action at this time.
0 commit comments