-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudy_timer.py
More file actions
29 lines (24 loc) · 910 Bytes
/
study_timer.py
File metadata and controls
29 lines (24 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import time
import winsound # For Windows beep sound
def study_timer(duration_minutes):
# Convert minutes to seconds
total_seconds = duration_minutes * 60
print(f"Study timer started for {duration_minutes} minutes.")
try:
# Countdown
while total_seconds > 0:
minutes, seconds = divmod(total_seconds, 60)
print(f"\r{minutes:02}:{seconds:02}", end="")
time.sleep(1)
total_seconds -= 1
# Beep sound when countdown reaches zero
print("\nTime's up! Beep!")
winsound.Beep(1000, 1000) # Frequency = 1000 Hz, Duration = 1000 ms (1 second)
except KeyboardInterrupt:
print("\nTimer stopped manually.")
# Get user input for study duration
try:
duration = int(input("Enter the study duration in minutes: "))
study_timer(duration)
except ValueError:
print("Please enter a valid number.")