SRE/faci(F).py
2025-05-19 20:17:54 +08:00

20 lines
625 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#错误……
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)))