Skip to content

Instantly share code, notes, and snippets.

@AO8
Created November 1, 2019 18:02
Show Gist options
  • Save AO8/bdd6535d68f6e319b55268e4d769843c to your computer and use it in GitHub Desktop.
Save AO8/bdd6535d68f6e319b55268e4d769843c to your computer and use it in GitHub Desktop.
A simple Python countdown clock.
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