-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-CountDown-Timer.py
More file actions
31 lines (24 loc) · 819 Bytes
/
6-CountDown-Timer.py
File metadata and controls
31 lines (24 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#Step 1: import time modul
import time
#Step 2: Create Function for display Countdown
def Countdown_timer(seconds):
while seconds:
#Calculate Minutes and seconds
mins, secs=divmod(seconds, 60)
#format as mm:secs
#print the countdown timer
#end="\r" is used to print on the same line
#f-string is used to format the string
#f"{mins:02d}:{secs:02d}" is used to format the string with 2 digits
timer=f"{mins:02d}:{secs:02d}"
print(timer,end="\r")
#wait for 1 seconds
time.sleep(1)
seconds-=1
print("Times Up!")
try:
total_time=int(input("Enter countdown time in seconds:"))
Countdown_timer(total_time)
except ValueError:
#Handle invalid input
print("Invaild input")