Last active
February 12, 2022 14:28
-
-
Save maxtacu/b10a5362d35e444ed393bb5ad0ff4f2f to your computer and use it in GitHub Desktop.
Python countdown timer https://youtu.be/9QSo3F6sM1w
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 argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-t', '--time', type=int, required=True, help="Time in seconds") | |
parser.add_argument('-o', '--output',default="counter.txt", help="Output file") | |
args = parser.parse_args() | |
def countdown(t): | |
while t: | |
timefile = open(args.output, "w") | |
mins, secs = divmod(t, 60) | |
if mins > 59: | |
hours, mins = divmod(mins, 60) | |
else: | |
hours = 0 | |
timeformat = f"{hours:02d}:{mins:02d}:{secs:02d}" | |
timefile.write(timeformat) | |
timefile.close() | |
time.sleep(1) | |
t -= 1 | |
countdown(args.time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment