Here is my code:
def getRow(rowIndex):
if rowIndex == 0:
return [1]
if rowIndex == 1:
return [1,1]
def f(n,r):
if n == 1:
print(r)
return r
r = [1]+[r[i] + r[i+1] for i in range(len(r)-1)]+[1]
f(n-1,r)
return f(rowIndex,[1,1])
print(getRow(4))
That print(r)
function worked perfectly and gave the right answer, however, the return r
statement just didn't work at all. Anyone knows why is this happening?
Desired output: [1,4,6,4,1]
Actual output: null
I would like to know why doesn't the return r
statement in the f
function return anything through the return f(rowIndex,[1,1])
statement.