Created
July 13, 2023 23:32
-
-
Save nick3499/0971b52f808fc984c6f43c36013657ed to your computer and use it in GitHub Desktop.
Countdown Timer: time.sleep(), sys.argv()
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
#!/bin/python3 | |
'''Countdown Timer | |
`$ python3 countdown.py 15` <-- 15 min timer example''' | |
from time import sleep | |
from sys import argv | |
tot_secs = int(argv[1]) * 60 # convert minute(s) string | |
def countdown(tot_secs): | |
'''Countdown total seconds in 5 sec increments format to digital clock format''' | |
while tot_secs: | |
mins, secs = divmod(tot_secs, 60) # (2, 0) --> 120 sec / 60 with zero secs remaining (remainder) | |
print(f'{mins:2d}:{secs:02d}') # 2:00 (convert `mins` and `secs` to digital format) | |
sleep(5) # pause 5 secs for time sequence | |
tot_secs -= 5 # subtract 5 from total seconds | |
print('\x1b[1;7;31m END \x1b[0m') # print END when total seconds reaches zero | |
countdown(tot_secs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment