Skip to content

Python code snippet – How to set a timer in while loop ?

start_time = time.time()
seconds = input("Enter: ")
seconds = int(seconds)

while True:
    current_time = time.time()
    elapsed_time = current_time - start_time

    if elapsed_time > seconds:
        print("Finished iterating in: " + str(int(elapsed_time))  + " seconds")
See also  Python code snippet - How to say that an input needs to be a number ?

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.