How to Create a Countdown Timer in Python
# Create a Countdown Timer in Python
# 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('time up!!')
# input time in seconds
t = input("Enter the time in seconds: ")
# function call
countdown(int(t))
Output:
Enter the time value in seconds:
15
00:15
00:14
00:13
00:12
00:11
00:10
00:09
00:08
00:07
00:06
00:05
00:04
00:03
00:02
00:01
time up!!
About The Author
Shailendra Bramhvanshi, Founder at Techaroha Solutions Private Limited and CEO at Newtum Solutions Private Limited. BlockChain Experts with 12 years of IT Experience in of all aspects of running Organization and Project Management. I have created different coins to help the business to bring more trust. Recently deployed a stable coin in India TrueINR and working on few cryptocurrency exchanges. My Team is being rated as a top 10 blockchain service provider in India by Silicon India