Python : IndexError: list index out of range -


i'm relatively new python. getting error when tried implementing following code. don't understand error.

def coinchange(s,m,n):      dp = [[0 x in range(m)] x in range(n+1)]      in range(m):         dp[0][i] = 1      in range(1,n+1):         j in range(m):             if >= s[j]:                 dp[i][j] = dp[i-1][j] + dp[i][i-s[j]]             else:                 dp[i][j] = dp[i-1][j]      return dp[i][j]   s = [1,3,5] m = len(s) n = 11  print(coinchange(s,m,n))    error i'm getting:     traceback (most recent call last):     file "c:\users\saiv\coinchange.py", line 24, in <module>        print(coinchange(s,m,n))     file "c:\users\saiv\coinchange.py", line 13, in coinchange     dp[i][j] = dp[i-1][j] + dp[i][i-s[j]]      indexerror: list index out of range 

the error means have tried retrieve value of index in list (as in my_list[index]) does not exist. assumed fatal error sensible languages, , such program terminates immediately. read rest of exception message better idea of issue is.


Comments

Popular posts from this blog

Combining PHP Registration and Login into one class with multiple functions in one PHP file -

Android volley - avoid multiple requests of the same kind to the server? -

magento2 - Magento 2 admin grid add filter to collection -