fork download
  1. def pascTri(n):
  2. if (n==1):
  3. return [[1]]
  4. else:
  5. p=pascTri(n-1)
  6. l=len(p)
  7. q=p[l-1]
  8. k=len(q)
  9. res=[1]
  10. for i in range(1,l):
  11. res+=[q[i]+q[i-1]]
  12. res+=[1]
  13. return p+[res]
  14.  
  15. def printPascTri(n):
  16. tri=pascTri(n)
  17. for a in tri:
  18. for x in a:
  19. print(x,end=' ')
  20. print('')
  21.  
  22. printPascTri(10)
  23.  
  24.  
  25.  
Success #stdin #stdout 0.01s 27712KB
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 
1 7 21 35 35 21 7 1 
1 8 28 56 70 56 28 8 1 
1 9 36 84 126 126 84 36 9 1