Skip to content

Instantly share code, notes, and snippets.

@abzrg
Last active September 3, 2022 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abzrg/ffea4f2a34ff111670b30b5bd0d37906 to your computer and use it in GitHub Desktop.
Save abzrg/ffea4f2a34ff111670b30b5bd0d37906 to your computer and use it in GitHub Desktop.
A simple timer for me that counts from zero upward!
#!/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