PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
Please note: Khayam ; the persian mathematician worked on and discovered the binomial expanssion Coefficients at almost the same time as Pascal .Therefor the internatinally recognized name for the triangle is:The Khayam_Pascal triangle.
Please enter the order of binomial of which you want to get the coefficients of_ 2 or more(I have tried upto 29 without time out )_
Out put is almost a triangle for upto order of 8 on my pone although thecode can calculate upto 29 on my connection before timeout.
I have used the method employed by Khayam.
"""
n0=[1]
n1=[1,1]
n2=n1[:]
order = int(input())
print(" "*2*(order+1),n0)
print(" "*2*(order ),n1)
for i in range(order-1):
next=[]
next.append(1)
for i in range(len(n2)-1):
next.append(n2[i] +n2[i+1])
next.append (1)
print(" "*2*(order-((i+1))),next)
n2=next[:]
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run