fork download
  1. def pascalsTriangle(n):
  2. if n == 0:
  3. return []
  4. elif n == 1:
  5. return [1]
  6. else:
  7. new_row = [1]
  8. last_row = pascalsTriangle(n-1)
  9. for i in range(len(last_row)-1):
  10. new_row.append(last_row[i] + last_row[i+1])
  11. new_row += [1]
  12. return new_row
  13.  
  14.  
  15. n = 8
  16. for i in range(n):
  17. print(pascalsTriangle(i))
  18.  
  19.  
  20.  
  21.  
  22.  
Success #stdin #stdout 0.03s 9568KB
stdin
Standard input is empty
stdout
[]
[1]
[1, 1]
[1, 2, 1]
[1, 3, 3, 1]
[1, 4, 6, 4, 1]
[1, 5, 10, 10, 5, 1]
[1, 6, 15, 20, 15, 6, 1]