Created
November 1, 2019 18:02
-
-
Save AO8/bdd6535d68f6e319b55268e4d769843c to your computer and use it in GitHub Desktop.
A simple Python countdown clock.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from time import sleep | |
def countdown(seconds): | |
while seconds > -1: | |
mins, secs = divmod(seconds, 60) | |
formatted_time = f"{mins:02d}:{secs:02d}" | |
if seconds > 3: | |
print(formatted_time, end="\r") | |
else: | |
print(formatted_time, file=sys.stderr, end="\r") # print final 3 secs in red | |
sleep(1) | |
seconds -= 1 | |
print("Countdown complete!") | |
user_input = int(input("Enter number of seconds to count down from: ")) | |
countdown(user_input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment