添加 faci
This commit is contained in:
parent
45bd47eb58
commit
319c35afd3
20
faci
Normal file
20
faci
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#错误……
|
||||||
|
import time
|
||||||
|
|
||||||
|
def cal_time(func): #传递被装饰函数
|
||||||
|
def transfer(*args): #传递被装饰函数的参数
|
||||||
|
start_time = time.time()
|
||||||
|
result = func(*args)
|
||||||
|
end_time = time.time()
|
||||||
|
# consume_time = end_time - start_time
|
||||||
|
print(f"运行时间: {end_time - start_time:.3f}秒")
|
||||||
|
return result
|
||||||
|
return transfer
|
||||||
|
@cal_time
|
||||||
|
def fb_sq(n):
|
||||||
|
if n <= 1:
|
||||||
|
yield n # 递归出口,直接返回n的值
|
||||||
|
else:
|
||||||
|
# 递归获取前两项的值并相加
|
||||||
|
yield next(fb_sq(n-1)) + next(fb_sq(n-2))
|
||||||
|
print(next(fb_sq(10)))
|
Loading…
x
Reference in New Issue
Block a user