-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathstopwatch.py
More file actions
22 lines (21 loc) · 732 Bytes
/
stopwatch.py
File metadata and controls
22 lines (21 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# A stopwatch that tracks the amount of time between hits
# of the "enter" key, with each key hit starting a new
# “lap” on the timer and Print the lap number, total time, and lap time.
import time
print("Hit \"enter\" to begin the program")
print("Hit \"enter\" again to the stopwatch")
input()
print("Program is already running")
startTime = time.time()
lastTime = startTime
lapNum = 1
try:
while True:
input()
lapTime = round(time.time() - lastTime, 2)
totalTime = round(time.time() - startTime, 2)
print('Lap #%s: %s (%s)' % (lapNum, totalTime, lapTime), end='')
lapNum += 1
lastTime = time.time() # reset the last lap time
except KeyboardInterrupt:
print('\nDone.')