我想用Python的Class来做一个计时器, 将Class命名为Timer, 用start method 和 end method, t = timer, t.start(), t.end(),t.end() 停止计时器并将记录的时间到终端显示, 当计时器已经开始运行时t.start()给出error,当计时器计时器没有运行时t.end()给出error,timer可以设置显示小时,分钟或者秒, 而且显示最近一次的计时。Python版本为python 2.7, 谢谢大家了!
1 回答
![?](http://img1.sycdn.imooc.com/545846070001a15002200220-100-100.jpg)
GCT1015
TA贡献1827条经验 获得超4个赞
import time
def start_sleep():
time.sleep(3)
if __name__ == '__main__':
#The start time
start = time.clock()
#A program which will run for 3 seconds
start_sleep()
#The End time
end = time.clock()
print("The function run time is : %.03f seconds" %(end-start))
# End
添加回答
举报
0/150
提交
取消