1- # Hello!
1+ import time
2+
3+ def countdownTimer ():
4+ # get the number of seconds
5+ no_of_secs = int (input ('How many seconds?: ' ))
6+ while no_of_secs :
7+ if no_of_secs < 60 :
8+ # calculate the number of hours, minutes and seconds
9+ hrs = no_of_secs // 3600
10+ mins = no_of_secs // 60
11+ secs = no_of_secs % 60
12+ # format the hours, minutes
13+ # and seconds to be displayed
14+ timer = '%02d:%02d:%02d' % (hrs , mins , secs )
15+ print (timer , end = '\r ' )
16+ # delay execution of code by one second
17+ time .sleep (1 )
18+ # countdown the number of seconds
19+ no_of_secs -= 1
20+ elif 60 <= no_of_secs < 3600 :
21+ # calculate the number of hours, minutes and seconds
22+ hrs = no_of_secs // 3600
23+ mins = no_of_secs // 60
24+ secs = no_of_secs % 60
25+ # format the hours, minutes
26+ # and seconds to be displayed
27+ timer = '%02d:%02d:%02d' % (hrs , mins , secs )
28+ print (timer , end = '\r ' )
29+ # delay execution of code by one second
30+ time .sleep (1 )
31+ # countdown the number of seconds
32+ no_of_secs -= 1
33+ elif 3600 <= no_of_secs <= 86400 :
34+ # calculate the number of hours, minutes and seconds
35+ hrs = no_of_secs // 3600
36+ mins = (no_of_secs % 3600 ) // 60
37+ secs = (no_of_secs % 3600 ) % 60
38+ # format the hours, minutes
39+ # and seconds to be displayed
40+ timer = '%02d:%02d:%02d' % (hrs , mins , secs )
41+ print (timer , end = '\r ' )
42+ # delay execution of code by one second
43+ time .sleep (1 )
44+ # countdown the number of seconds
45+ no_of_secs -= 1
46+ print ('Time Up!' )
47+
48+ countdownTimer ()
0 commit comments