想用装饰器给这个函数计算运行时间,为什么一直不对啊,刚学,下面的错误也看不懂,谢谢各位
from time import *
def time_master(func):
def time_(*args,**kwargs):
print("开始调用程序")
start=time()
func(*args,**kwargs)
stop=time()
print("结束调用,共用时{:.5f}".format(stop-start))
return time_
@time_master
def rabbit(m):
if m<4:
return m
else:
return rabbit(m-3)+rabbit(m-1)
print(rabbit(5))
错误显示
开始调用程序
开始调用程序
结束调用,共用时0.00000
开始调用程序
开始调用程序
结束调用,共用时0.00000
开始调用程序
结束调用,共用时0.00000
Traceback (most recent call last):
File "C:\Users\13113\Desktop\递归.py", line 40, in <module>
print(rabbit(5))
^^^^^^^^^
File "C:\Users\13113\Desktop\递归.py", line 29, in time_
func(*args,**kwargs)
File "C:\Users\13113\Desktop\递归.py", line 38, in rabbit
return rabbit(m-3)+rabbit(m-1)
^^^^^^^^^^^
File "C:\Users\13113\Desktop\递归.py", line 29, in time_
func(*args,**kwargs)
File "C:\Users\13113\Desktop\递归.py", line 38, in rabbit
return rabbit(m-3)+rabbit(m-1)
~~~~~~~~~~~^~~~~~~~~~~~
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
进程已结束,退出代码1