Python Program to Create a Countdown Timer


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co

A countdown timer is a tool that counts down from a specified amount of time to zero, often used to measure the duration of an event or task. Countdown timers are commonly used in various situations, such as cooking, exercising, taking a test, or presenting.


Python Code :

The Below Python program creates a countdown timer using the time module:


import time

def countdown_timer(seconds):
    """
    Displays a countdown timer for the specified number of seconds.
    """
    while seconds > 0:
        print(seconds)
        time.sleep(1)
        seconds -= 1
    print("Time's up!")

You can use this function by passing in the number of seconds you want to count down from:


countdown_timer(10)

This will display a countdown timer starting from 10 seconds and counting down to 0, like this:


10
9
8
7
6
5
4
3
2
1
Time's up!

You can customize the message that is displayed when the timer reaches 0 by changing the argument to the final print statement.


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co