-
Notifications
You must be signed in to change notification settings - Fork 2
/
SimpleStopWatch.py
44 lines (35 loc) · 947 Bytes
/
SimpleStopWatch.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
41
42
43
44
#This program illustrates a stopwatch
import time
print('Press ENTER to begin, Press Ctrl + C to stop')
while True:
try:
input() #For ENTER
starttime = time.time()
print('Started')
except KeyboardInterrupt:
print('Stopped')
endtime = time.time()
print('Total Time:', round(endtime - starttime, 2),'secs')
break
# Press enter to start and stop the watch
"""
import time
print('Press Enter to begin, Press Enter again to stop')
if input()=='':
starttime = time.time()
print('Started')
while True:
val=input() #For ENTER
if val=='':
print('Stopped')
endtime = time.time()
print('Total Time:', round(endtime - starttime, 2),'secs')
break
"""
"""
Output:
Press Enter to begin, Press Enter again to stop
Started
Stopped
Total Time: 1.05 secs
"""