forked from Graey/pythoncharmers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaptimer.py
40 lines (29 loc) · 776 Bytes
/
laptimer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# importing libraries
import time
# Timer starts
starttime=time.time()
lasttime=starttime
lapnum=1
print("Press ENTER to count laps.\nPress CTRL+C to stop")
try:
while True:
# Input for the ENTER key press
input()
# The current lap-time
laptime=round((time.time() - lasttime), 2)
# Total time elapsed
# since the timer started
totaltime=round((time.time() - starttime), 2)
# Printing the lap number,
# lap-time and total time
print("Lap No. "+str(lapnum))
print("Total Time: "+str(totaltime))
print("Lap Time: "+str(laptime))
print("*"*20)
# Updating the previous total time
# and lap number
lasttime=time.time()
lapnum+=1
# Stopping when CTRL+C is pressed
except KeyboardInterrupt:
print("Done")