Skip to content

How to make a minute counter in Python?

import time
import sys

def run_timer(seconds):
    for remaining in range(seconds, 0, -1):
        sys.stdout.write("\r")
        minutes = 0
        seconds = remaining
        if remaining > 60:
            minutes = int(seconds/60)
            seconds = int(seconds%60)
        else:
            seconds = remaining
        sys.stdout.write("{:2d} minutes {:2d} seconds remaining.".format(minutes,seconds)) 
        sys.stdout.flush()
        time.sleep(0.1)
    sys.stdout.write("Timer complete") 

run_timer(60)

or with just while loop..

counter = 1
print(counter)
import time
while True:
    time.sleep(60)
    counter += 1
    print(counter)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.