diff --git a/Countdown Timer/README.md b/Countdown Timer/README.md new file mode 100644 index 00000000..2b7ce870 --- /dev/null +++ b/Countdown Timer/README.md @@ -0,0 +1,17 @@ +# Countdown Timer + +This program takes in the number of seconds to countdown and displays a message when the time elapses. + +# Prerequisites + +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. + +# How to run the script + +Running the script is pretty easy, open a terminal in the folder where your script is located and run the following command : + +`python timer.py` + +# Author's name + +[KOTHA V V S AAKASH](https://github.com/AakashKotha) diff --git a/Countdown Timer/timer.py b/Countdown Timer/timer.py new file mode 100644 index 00000000..43993c27 --- /dev/null +++ b/Countdown Timer/timer.py @@ -0,0 +1,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() diff --git a/README.md b/README.md index 143e4d03..e94f5b33 100644 --- a/README.md +++ b/README.md @@ -68,9 +68,9 @@ Incase there is something that needs to be followed while executing the python s | Wikipedia Data Extractor | [Wikipedia Data Extractor](https://github.com/DhanushNehru/Python-Scripts/tree/master/Wikipedia%20Data%20Extractor) | Simple Wikipedia data extractor script to get output in your IDE | | Youtube Downloader | [Youtube Downloader](https://github.com/DhanushNehru/Python-Scripts/tree/master/Youtube%20Downloader) | Download any video from [YouTube](https://youtube.com) in video or audio format! | | Weight Coverter | [Weight Converter](https://github.com/WatashiwaSid/Python-Scripts/tree/master/Weight%20Converter) | Simple GUI script to convert weight in different measurement units | - +| Countdown Timer | [Countdown Timer](https://github.com/DhanushNehru/Python-Scripts/tree/master/Countdown%20Timer) | Displays a message when the Input time elapses | ### Project Contributors - \ No newline at end of file +