forked from DhanushNehru/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.py
48 lines (46 loc) · 1.41 KB
/
timer.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import time
def countdownTimer():
# get the number of seconds
no_of_secs = int(input('How many seconds?: '))
while no_of_secs:
if no_of_secs < 60:
# calculate the number of hours, minutes and seconds
hrs = no_of_secs // 3600
mins = no_of_secs // 60
secs = no_of_secs % 60
# format the hours, minutes
# and seconds to be displayed
timer = '%02d:%02d:%02d' %(hrs, mins, secs)
print(timer, end='\r')
# delay execution of code by one second
time.sleep(1)
# countdown the number of seconds
no_of_secs -= 1
elif 60 <= no_of_secs < 3600:
# calculate the number of hours, minutes and seconds
hrs = no_of_secs // 3600
mins = no_of_secs // 60
secs = no_of_secs % 60
# format the hours, minutes
# and seconds to be displayed
timer = '%02d:%02d:%02d' %(hrs, mins, secs)
print(timer, end='\r')
# delay execution of code by one second
time.sleep(1)
# countdown the number of seconds
no_of_secs -= 1
elif 3600 <= no_of_secs <= 86400:
# calculate the number of hours, minutes and seconds
hrs = no_of_secs // 3600
mins = (no_of_secs % 3600) // 60
secs = (no_of_secs % 3600) % 60
# format the hours, minutes
# and seconds to be displayed
timer = '%02d:%02d:%02d' %(hrs, mins, secs)
print(timer, end='\r')
# delay execution of code by one second
time.sleep(1)
# countdown the number of seconds
no_of_secs -= 1
print('Time Up!')
countdownTimer()