Last active
September 3, 2022 17:55
-
-
Save abzrg/ffea4f2a34ff111670b30b5bd0d37906 to your computer and use it in GitHub Desktop.
A simple timer for me that counts from zero upward!
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
#!/usr/bin/env python3 | |
"""\ | |
. . . | |
timer | |
. . . | |
A timer that counts from time 0 to the final time | |
USAGE: timer <secs> | |
""" | |
from sys import argv | |
from time import sleep | |
def main() -> int: | |
"""Main function""" | |
# Get end time from command-line | |
try: | |
end_time: int = int(argv[1]) | |
except ValueError: | |
print("Usage: timer <secs>") | |
return 1 | |
print(f"Set timer for {end_time} seconds") | |
sec: int = 0 | |
minute: int = 0 | |
hour: int = 0 | |
for _ in range(1, end_time + 1): | |
sec += 1 | |
if minute == 60: | |
hour += 1 | |
minute = 0 | |
if sec == 60: | |
minute += 1 | |
sec = 0 | |
print(f"Time: {hour:02d}:{minute:02d}:{sec:02d}", end="\r") | |
sleep(1) | |
print(f"Time: {hour:02d}:{minute:02d}:{sec:02d}") | |
return 0 | |
if __name__ == "__main__": | |
raise SystemExit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment