-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
29 lines (25 loc) · 888 Bytes
/
main.py
File metadata and controls
29 lines (25 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Countdown Timer: Counting down from a user-provided input to 0
import time
def get_start_time():
# Prompts the user to input a start time in seconds
# Mitigates ValueError
while True:
start_time = input("How many seconds would you like to count down from?: ")
try:
start_time = int(start_time)
return start_time
except ValueError:
print("Please input a valid number of seconds! ")
def countdown(seconds):
# Counts down from the provided start time
# Waits 1 second after each second printed
for seconds in reversed(range(1, seconds + 1)):
print(f"There are {seconds} seconds remaining...")
time.sleep(1)
print("Time's Up!")
def main():
# Main function handles the project flow
start_time = get_start_time()
countdown(start_time)
if __name__ == "__main__":
main()