Created
August 8, 2023 11:07
-
-
Save RDCH106/3855cdf3201fcba7ef3356d9931d1a4c to your computer and use it in GitHub Desktop.
Simple and configurable countdown for the Command Line Interface (CLI)
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
# -*- coding: utf-8 -*- | |
import time | |
def countdown_sleep(second: int): | |
# check second is natural number (contains 0) | |
if not isinstance(second, int) or second < 0: | |
raise ValueError("'second' should be a natural number (contains 0). second: %s" % second) | |
# countdown | |
for i in range(second, 0, -1): | |
print(f"\rWait... {i} ", end="", flush=True) | |
time.sleep(1) | |
print(f"\rGo! ", flush=True) | |
# Try countdown | |
if __name__ == "__main__": | |
countdown_sleep(10) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment