Answers for "how to make a stopwatch in python"

3

hwo to creat a stopwatch using python

# Create a stopwatch

# Import a module called as time

import time

# create all the variables

day = 0
hour = 0
min = 0
sec = 0

# Display the headings

print("D - H - M - S")
print()

# Create an infinite loop

while True:

    # Create the main part of the stopwatch

    time.sleep(1)

    if sec == 59:
       sec = -1
       min = min + 1

    sec = sec + 1
    if min == 60:
        min = 0
        hour = hour + 1

    if hour == 24:
        hour = 0
        day = day + 1
    print(day, "-", hour, "-", min, "-", sec)
Posted by: Guest on August-25-2020
3

python how to make a stopwatch

import time
import sys

time_start = time.time()
seconds = 0
minutes = 0

running = True

while running:
    try:
        sys.stdout.write("\r{minutes} Minutes {seconds} Seconds".format(minutes=minutes, seconds=seconds))
        sys.stdout.flush()
        time.sleep(1)
        seconds = int(time.time() - time_start) - minutes * 60
        if seconds >= 60:
            minutes += 1
            seconds = 0
    except KeyboardInterrupt as e:
        running = False
Posted by: Guest on August-01-2020
0

how to make a stopwatch in python

import time

time_to_stop = 10 #seconds
for x in range(1, time_to_stop+1):
    print(x)
    time.sleep(1)
Posted by: Guest on October-05-2021
0

python stopwatch

1 # latest_tutorial.py
 2 
 3 import time
 4 from reader import feed
 5 
 6 def main():
 7     """Print the latest tutorial from Real Python"""
 8     tic = time.perf_counter()
 9     tutorial = feed.get_article(0)
10     toc = time.perf_counter()
11     print(f"Downloaded the tutorial in {toc - tic:0.4f} seconds")
12 
13     print(tutorial)
14 
15 if __name__ == "__main__":
16     main()
Posted by: Guest on October-11-2020
0

how to make a stopwatch in pythoon

import time

now = time.time()
future = now + 10
while time.time() < future:
    # do stuff
    pass
Posted by: Guest on July-16-2020

Python Answers by Framework

Browse Popular Code Answers by Language