Skip to content

Commit 34d7d08

Browse files
authored
Merge pull request larymak#51 from Mannuel25/main
Addition of countdown timer
2 parents 6a3abcd + b820d1e commit 34d7d08

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

Countdown Timer/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Countdown Timer
2+
3+
This program takes in the number of seconds to countdown and displays a message when the time elapses.
4+
5+
# Prerequisites
6+
7+
It requires no prerequisites, you only need to run the script. If you don't have Python installed, you can visit [here](https://www.python.org/downloads/) to download Python.
8+
9+
# How to run the script
10+
11+
Running the script is pretty easy, open a terminal in the folder where your script is located and run the following command :
12+
13+
`python timer.py`
14+
15+
# Sample use of the script
16+
17+
![alt text](https://github.com/Mannuel25/Python-project-Scripts/blob/main/Countdown%20Timer/screenshot_1.png)
18+
19+
![alt text](https://github.com/Mannuel25/Python-project-Scripts/blob/main/Countdown%20Timer/screenshot_2.png)
20+
21+
# Author's name
22+
23+
[Tanimowo Emmanuel](https://github.com/Mannuel25)

Countdown Timer/screenshot_1.png

11 KB
Loading

Countdown Timer/screenshot_2.png

11.6 KB
Loading

Countdown Timer/timer.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)