秒表
1 import time 2 print("请按下回车键开始,然后在你要标记的时间点按下回车键,用Ctrol-C退出") 3 input() 4 print('开始喽!') 5 6 startTime = time.time() 7 lastTime = startTime 8 lapNum = 1 9 try: 10 while True: 11 input() 12 lapTime = round(time.time()-lastTime,2) 13 totalTime = round(time.time()-startTime,2) 14 print('记录#%s: %ss \t(%ss)' %(lapNum,totalTime,lapTime),end='') 15 lapNum +=1 16 lastTime = time.time() 17 18 except KeyboardInterrupt: 19 print('\n恭喜你完成了本次记录!')