I'm trying to do a recursive function that generates a pascal's triangle up till the nth row, n being the user input. This is my code so far:
def printPascal(l,n): while n != 1: temp = [None]*(len(l)+1) temp[0] = 1 temp[len(l)] = 1 for i in range(1,len(temp)-1): temp[i] = l[i] + l[i-1] l = temp print(temp) n = n-1 printPascal(l,n) n = int(input("Enter a value for n:")) l = [1,1] printPascal(l,n) And this is the error it gives me:
Traceback (most recent call last): File "C:\Users\User\Desktop\test.py", line 16, in <module> printPascal(l,n) File "C:\Users\User\Desktop\test.py", line 11, in printPascal printPascal(l,n) File "C:\Users\User\Desktop\test.py", line 7, in printPascal temp[i] = l[i] + l[i-1] TypeError: unsupported operand type(s) for +: 'NoneType' and 'int' The thing is i kinda understand the issue and have tried tracing it to no avail. I know that somehow in the temp[i] = l[i] + l[i-1] code either the l[i] or l[i -1] is a "None" and i don't know why.
Thanks for your time and help in this little predicament of mine.