我想用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
添加回答
舉報
0/150
提交
取消