From 3c32ec10d647a55fb96f03bfb676b26787ea7978 Mon Sep 17 00:00:00 2001 From: KelvinQiu Date: 2022年3月19日 14:41:12 +0800 Subject: [PATCH 1/2] countdown_plus --- projects/Countdown_timer/main.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/projects/Countdown_timer/main.py b/projects/Countdown_timer/main.py index 06c48e22c..2dd62789e 100644 --- a/projects/Countdown_timer/main.py +++ b/projects/Countdown_timer/main.py @@ -1,15 +1,24 @@ 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: + 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: ') -countdown(int(t)) \ No newline at end of file +countdown(int(t)) From 70804663b2ade9463859a2f93b6188d920413c95 Mon Sep 17 00:00:00 2001 From: KelvinQiu Date: 2022年3月19日 14:59:19 +0800 Subject: [PATCH 2/2] countdown_plus_1 --- projects/Countdown_timer/main.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/projects/Countdown_timer/main.py b/projects/Countdown_timer/main.py index 2dd62789e..f10643407 100644 --- a/projects/Countdown_timer/main.py +++ b/projects/Countdown_timer/main.py @@ -1,11 +1,10 @@ import time - def countdown(t): while int(t): - if t> 10: + if t> 10: # more than 10 seconds mins, secs = divmod(t, 60) - timer = '{:02d}:{:02d}'.format(mins, secs) + timer = '{:02d}:{:02d}'.format(mins,secs) print(timer, end="\r") time.sleep(1) t -= 1 @@ -18,7 +17,6 @@ def countdown(t): print('Timer completed!') +t = int(input('Enter the time in seconds: ')) -t = input('Enter the time in seconds: ') - -countdown(int(t)) +countdown(int) \ No newline at end of file

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