A straightforward and easy-to-use console-based countdown timer written in Python. This utility allows you to set a duration in seconds, and it will count down, displaying the remaining time in a MM:SS format.
- Customizable Duration: Set the timer for any number of seconds.
- Minute:Second Display: Shows the time in a clear
MM:SSformat. - Real-time Countdown: Updates every second.
- User-Friendly Interface: Simple input prompt and "Time's up!" message.
- Error Handling: Catches invalid input (non-numbers or non-positive numbers).
The script uses Python's time module to pause execution for one second at a time, creating the countdown effect. It calculates minutes and seconds using the divmod() function for clean formatting.
- Python 3.x
- Save the Code:
- Copy the entire Python code for the timer into a file named
countdown_timer.py(or any other name ending with.py).
- Copy the entire Python code for the timer into a file named
- Open Your Terminal/Command Prompt:
- Navigate to the directory where you saved
countdown_timer.pyusing thecdcommand.- Example (Windows):
cd C:\Users\YourUser\Documents\my_scripts - Example (macOS/Linux):
cd ~/Documents/my_scripts
- Example (Windows):
- Navigate to the directory where you saved
- Run the Script:
- Execute the Python script using the command:
python countdown_timer.py
- Execute the Python script using the command:
- After running the script, you will be prompted to enter the duration:
Enter the duration of the timer in seconds: - Type a positive integer (e.g.,
60for one minute,300for five minutes) and press Enter. - The timer will start counting down in the console:
00:59 00:58 ... - Once the time reaches zero, it will print "Time's up!".
- Sound Notification: Play a sound when the timer finishes.
- Pause/Resume Functionality: Allow the user to pause and resume the countdown.
- Multiple Timers: Support running multiple timers concurrently.
- Background Operation: Run the timer in the background while the user does other tasks.
- GUI: Create a graphical user interface instead of a console-based one using libraries like Tkinter, PyQt, or Kivy.