How To Create a Countdown Timer Using Python? Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report In this article, we will see how to create a countdown timer using Python. The code will take input from the user regarding the length of the countdown in seconds. After that, a countdown will begin on the screen of the format âminutes: secondsâ. We will use the time module here. Approach In this project, we will be using the time module and its sleep() function. Follow the below steps to create a countdown timer: Step 1: Import the time module. Step 2: Then ask the user to input the length of the countdown in seconds. Step 3: This value is sent as a parameter âtâ to the user-defined function countdown(). Any variable read using the input function is a string. So, convert this parameter to âintâ as it is of string type. Step 4: In this function, a while loop runs until time becomes 0. Step 5: Use divmod() to calculate the number of minutes and seconds. You can read more about it here. Step 6: Now print the minutes and seconds on the screen using the variable timeformat. Step 7: Using end = â\râ we force the cursor to go back to the start of the screen (carriage return) so that the next line printed will overwrite the previous one. Step 8: The time.sleep() is used to make the code wait for one sec. Step 9: Now decrement time so that the while loop can converge. Step 10: After the completion of the loop, we will print âFire in the holeâ to signify the end of the countdown. Below is the implementation of the above approach Python3 # import the time module import time # define the countdown func. def countdown(t): while t: mins, secs = divmod(t, 60) timer = '{:02d}:{:02d}'.format(mins, secs) print(timer, end="\r") time.sleep(1) t -= 1 print('Fire in the hole!!') # input time in seconds t = input("Enter the time in seconds: ") # function call countdown(int(t)) Output: https://media.geeksforgeeks.org/wp-content/cdn-uploads/20200729151851/python-countdown-timer.webm Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century. Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve. Last Updated : 17 May, 2022 Like Article Save Article Previous Creating payment receipts using Python Next Convert emoji into text in Python Share your thoughts in the comments Add Your Comment Please Login to comment...