Matt
2013-07-24 16:57:54 UTC
I am trying to run my program which is a recursive function however im not sure how to run it(Total noob here) I run the program then the shell comes up and you can type whatever... doesn't show anything??? Please help...
This is the question im working on:
Create a program which with a function that implements Pascal's triangle. (Note: This will require you to use a recursive function!)
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
This is the code I have so far:
def triangle(n):
if n == 0:
return []
elif n == 1:
return [[1]]
else:
new_row = [1]
result = triangle(n-1)
last_row = result[-1]
for i in range(len(last_row)-1):
new_row.append(last_row[i] + last_row[i+1])
new_row += [1]
result.append(new_row)
return result
Thanks for your help!!!