Created
September 17, 2025 01:32
-
-
Save rlcarrca/6caa0962ce3db52f4f653b6f676a80b1 to your computer and use it in GitHub Desktop.
Countdown timer
This file contains hidden or 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 time | |
import datetime | |
def countdown_timer(x, now=datetime.datetime.now): | |
target = now() | |
one_second_later = datetime.timedelta(seconds=1) | |
for remaining in range(x, 0, -1): | |
target += one_second_later | |
print(datetime.timedelta(seconds=remaining), 'remaining', end='\r') | |
time.sleep((target - now()).total_seconds()) | |
print('\nTIMER ended') | |
if __name__ == '__main__': | |
countdown_timer(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment