Python Learning: Automate Boring Stuff with Python | Chapter 15: Prettified Stopwatch

I want to turn the clock back to when people lived in small villages and took care of each other.

Pete Seeger

And more coffee.. 4:05:04 PM


#usage Prettified_Stopwatch.py

import time , pyperclip

#TODO: start by enter
#TODO: store start time
#TODO: create lapNum
#TODO: loop until user ctrl c
input()
startTime = time.time()
lapNum = 0
lastTime = startTime
result = []
try:
    while True:
        input()
        lapTime = round(time.time() - lastTime, 2 )
        totalTime = round(time.time() - startTime, 2)
        mystr = "Lap #" + str(lapNum)+":"
        mystr += str(lapTime).rjust(5)
        mystr += " (" + str(totalTime).rjust(8)+")"
        result.append(mystr)
        lapNum += 1
        lastTime = time.time()

except KeyboardInterrupt:
    str = ""
    for line in result:
        str += line + "\n\n"
        print(str)
        pyperclip.copy(str)