为了账号安全,请及时绑定邮箱和手机立即绑定

Python自学新手请教大神:

Python自学新手请教大神:

千万里不及你 2023-02-18 21:17:15
我想用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 回答

?
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


查看完整回答
反对 回复 2023-02-20
  • 1 回答
  • 0 关注
  • 43 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信