def fibo(m):
dp = []
for i in range(m+1):
dp.append(0)
dp[0] = 1
dp[1] = 1
if(m>1):
for i in range(2,m+1):
dp[i] = dp[i-1] + dp[i -1]
return dp[m]
I am getting an error that says that the list index is out of bound can any resolve it and can post the correct code . Thanks.
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-92-ea67e751dd0e> in <module>()
12 return dp[m]
13
---> 14 fibo(0)
<ipython-input-92-ea67e751dd0e> in fibo(m)
6 dp.append(0)
7 dp[0] = 1
----> 8 dp[1] = 1
9 if(m>1):
10 for i in range(2,m+1):
IndexError: list assignment index out of range
range(m+1), but the tracebackrange(m).range(0+1)is just0. So you don't createdp[1]when you callfibo(0)