import time
def sum(n):
start = time.time()
sum = 0
for i in range(1, n + 1):
sum += i
end = time.time()
return sum, end - start
for i in range(100):
print("sum is:{}, requried {:.10f} seconds".format(sum(100000)[0],sum(100000)[1]))
简单求和。
最新推荐文章于 2022-02-11 18:08:59 发布