I'm experimenting with a few python programming elements and trying to produce an array of Catalan Numbers in the process.
I keep getting the aforementioned error, but I can't seem to reason out why or find any enlightening sources of info.
The function calculates the next element of list C using the current element, starting with C[0]=0.
I've reduced my code to make things simpler yet still preserve the error.
from math import *
C = []
C += [0]
def ppC(n,C): # increment list C
print( C[n] ) # list index out of range
C += [ C[n]*(4*n+2)/(n+2) ]
n += 1
ppC(n+1,C) # recursive
ppC(0,C) # RUN
1tontwice, but only one element was added toC.list.append(element)exists when you want to add a single element to a list, rather than doing `list += [element] (which creates an extra list). You might also want to look at the python style guide - things like odd spacing and using odd capitilisation for variable names makes code hard to read.