- 2
How to creat a countdown timer?
Can any one tell me how to creat a python based timer that start counting down from 10.
1 Antwort
+ 2
import time
# define the countdown function
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('end')
# input time in seconds
t = input("Enter the time in seconds: ")
# function call
countdown(int(t))