Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Timer implementation in python

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:


import time

time_to_wait = 30

while time_to_wait:
   seconds = time_to_wait % 60
   mins = time_to_wait // 60
   hours = mins * 60
   timer = '{:02d}:{:02d}:{:02d}'.format(hours, mins, seconds)
   print(timer, end="\r")
   time.sleep(1)
   time_to_wait -= 1

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

print(timer, end="\r")

\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

print("\r", timer, end="")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading