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")
        break
See also  Python code snippet - How to label column names and row names in pandas dataframe?

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.