import time
def calculate_time(total_time):
'''
total_time: total seconds
'''
spend_seconds = total_time % 60
totalminutes = total_time // 60
spend_minutes = totalminutes % 60
spend_hours = totalminutes // 60
return spend_hours, spend_minutes, spend_seconds
def main():
start_time = time.time()
‘’‘
相关程序
’‘’
end_time = time.time()
total_time = end_time - start_time
spend_hours, spend_minutes, spend_seconds = calculate_time(total_time)
print 'Total running time of the example: %.2f seconds ( %i hours %i minutes %.2f seconds )' \
% (total_time, spend_hours, spend_minutes, spend_seconds)
main() python计算程序运行时间
最新推荐文章于 2023-12-12 09:15:37 发布
本文介绍了一个简单的Python程序,用于计算程序的运行时间,并将其转换为小时、分钟和秒的形式进行展示。通过使用time模块,该程序能够准确地测量从开始到结束所需的时间。
5916

被折叠的 条评论
为什么被折叠?



