Skip to content

Commit 8d768c2

Browse files
committed
I created pomodoro timer
1 parent c213d87 commit 8d768c2

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Pomodoro-Timer/pomodoro.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import time
2+
import datetime
3+
4+
# Create a function that acts as a countdown
5+
def pomodoro_timer(task, h, m, s):
6+
# Calculate the total number of seconds
7+
total_seconds = h * 3600 + m * 60 + s
8+
9+
# Counter to keep track of the breaks
10+
break_count = 0
11+
12+
while total_seconds > 0:
13+
# Timer represents time left on the countdown
14+
timer = datetime.timedelta(seconds=total_seconds)
15+
# Prints the time left on the timer
16+
print(f"Focusing on {task}... Session time left: {timer}", end="\r")
17+
18+
# Delays the program one second
19+
time.sleep(1)
20+
21+
# Reduces total time by one second
22+
total_seconds -= 1
23+
24+
# Check if it's time for a break (only for the first 4 breaks)
25+
if total_seconds > 0 and break_count < 4 and total_seconds % 1500 == 0:
26+
print("\nNow on a short break!")
27+
time.sleep(300) # Short break for 5 minutes
28+
break_count += 1
29+
30+
# Check if it's time for a long break (after 4 sessions)
31+
elif total_seconds > 0 and break_count == 4 and total_seconds % 1500 == 0:
32+
print("\nNow on a long break!")
33+
time.sleep(1200) # Long break for 20 minutes
34+
break_count = 0 # Reset the break count for the next cycle
35+
36+
print("\nTask Completed")
37+
38+
# Inputs for hours, minutes, and seconds on the timer
39+
task = input("Enter the task to focus on: ")
40+
h = int(input("Enter the time in hours: "))
41+
m = int(input("Enter the time in minutes: "))
42+
s = int(input("Enter the time in seconds: "))
43+
pomodoro_timer(task, h, m, s)

0 commit comments

Comments
 (0)