每个人都可以解释为什么我打电话给fibDict(n = 10, {})
会出错,但是fib(10, d = {})
却没出错吗?
谢谢!
def fibDict(n, d):
if n in d.keys():
return d[n]
elif n == 0:
d[n] = 0
return d[n]
elif n == 1:
d[n] = 1
return d[n]
else:
d[n] = fibDict(n-1, d) + fibDict(n-2, d)
return d[n]