diff --git a/projects/Countdown_timer/main.py b/projects/Countdown_timer/main.py index 06c48e22c..f10643407 100644 --- a/projects/Countdown_timer/main.py +++ b/projects/Countdown_timer/main.py @@ -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)) \ No newline at end of file +countdown(int) \ No newline at end of file

AltStyle によって変換されたページ (->オリジナル) /