Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions projects/Countdown_timer/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import time

def countdown(t):
while t:
mins, secs = divmod(t, 60)
timer = '{:02d}:{:02d}'.format(mins,secs)
print(timer, end="\r")
time.sleep(1)
t -= 1
while int(t):
if t > 10: # more than 10 seconds
mins, secs = divmod(t, 60)
timer = '{:02d}:{:02d}'.format(mins,secs)
print(timer, end="\r")
time.sleep(1)
t -= 1
else: # less than 10 seconds
secs, ms = divmod(t * 100, 100)
timer = '{:02d}:{:02d}:{:02d}'.format(0, int(secs), int(ms))
print(timer, end="\r")
time.sleep(0.01)
t -= 0.01

print('Timer completed!')

t = input('Enter the time in seconds: ')
t = int(input('Enter the time in seconds: '))

countdown(int(t))
countdown(int)