|
1 | 1 | import time |
2 | 2 | import datetime |
| 3 | + |
| 4 | +# Create a function that acts as a countdown |
3 | 5 | def pomodoro_timer(task, h, m, s): |
4 | | -total_seconds = h * 3600 + m * 60 + s |
5 | | -break_count = 0 |
6 | | -while total_seconds > 0: |
7 | | -timer = datetime.timedelta(seconds=total_seconds) |
8 | | -print(f"Focusing on {task}... Session time left: {timer}", end="\r") |
9 | | -time.sleep(1) |
10 | | -total_seconds -= 1 |
11 | | -if total_seconds > 0 and break_count < 4 and total_seconds % 1500 == 0: |
12 | | -print("\nNow on a short break!") |
13 | | -time.sleep(300) |
14 | | -break_count += 1 |
15 | | -elif total_seconds > 0 and break_count == 4 and total_seconds % 1500 == 0: |
16 | | -print("\nNow on a long break!") |
17 | | -time.sleep(1200) |
18 | | -break_count = 0 |
19 | | -print("\nTask Completed") |
| 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 |
20 | 39 | task = input("Enter the task to focus on: ") |
21 | 40 | h = int(input("Enter the time in hours: ")) |
22 | 41 | m = int(input("Enter the time in minutes: ")) |
|
0 commit comments