我想用Python的Class來做一個(gè)計(jì)時(shí)器, 將Class命名為Timer, 用start method 和 end method, t = timer, t.start(), t.end(),t.end() 停止計(jì)時(shí)器并將記錄的時(shí)間到終端顯示, 當(dāng)計(jì)時(shí)器已經(jīng)開始運(yùn)行時(shí)t.start()給出error,當(dāng)計(jì)時(shí)器計(jì)時(shí)器沒有運(yùn)行時(shí)t.end()給出error,timer可以設(shè)置顯示小時(shí),分鐘或者秒, 而且顯示最近一次的計(jì)時(shí)。Python版本為python 2.7, 謝謝大家了!
1 回答

GCT1015
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊
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
添加回答
舉報(bào)
0/150
提交
取消