The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Build a Pomodoro timer in Python

Here’s a straightforward Pomodoro timer implemented in Python using the terminal. It includes work sessions and breaks, with countdown displayed every second.

python
import time def countdown(seconds): while seconds: mins, secs = divmod(seconds, 60) timer = f'{mins:02d}:{secs:02d}' print(f'r{timer}', end='') time.sleep(1) seconds -= 1 print() def pomodoro(work_duration=25, short_break=5, long_break=15, cycles=4): for cycle in range(1, cycles + 1): print(f'Starting work session {cycle}...') countdown(work_duration * 60) if cycle != cycles: print('Time for a short break.') countdown(short_break * 60) else: print('Time for a long break.') countdown(long_break * 60) print('Pomodoro sessions completed!') if __name__ == "__main__": print("Pomodoro Timer") pomodoro()

How it works:

  • By default, 25 minutes work, 5 minutes short break, 15 minutes long break, 4 cycles.

  • It prints a live countdown in MM:SS format in the terminal.

  • After completing 4 cycles, it signals the end.

You can modify pomodoro() parameters to customize durations or cycles. Let me know if you want a GUI version!

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About