I’m trying to implement a timer that counting down hours, mins and secs. I saw a similar implementation on the internet but still yet, there is nothing that printed to the terminal:
JavaScript
x
14
14
1
import time
2
3
time_to_wait = 30
4
5
while time_to_wait:
6
seconds = time_to_wait % 60
7
mins = time_to_wait // 60
8
hours = mins * 60
9
timer = '{:02d}:{:02d}:{:02d}'.format(hours, mins, seconds)
10
print(timer, end="r")
11
time.sleep(1)
12
time_to_wait -= 1
13
14
Advertisement
Answer
JavaScript
1
2
1
print(timer, end="r")
2
r
denotes carriage return so timer is printed and then (very quickly) wiped, to avoid that you should print carriage return first, that is please try using
JavaScript
1
2
1
print("r", timer, end="")
2