import time
print('Press ENTER to begin, Press Ctrl + C to stop')
while True:
try:
input()
starttime = time.time() #返回当前时间的时间戳
print('Started')
while True:
print('Time Elapsed: ', round(time.time() - starttime, 0), 'secs', end="\r")
time.sleep(1) # 推迟调用线程的运行 1s
except KeyboardInterrupt:
print('Stopped')
endtime = time.time()
print('Total Time:', round(endtime - starttime, 2), 'secs') #保留2位数
break
ctrl+c退出不了循环,不能结束