24 lines
472 B
Python
24 lines
472 B
Python
#python 3
|
|
|
|
def pascaltriangle(length):
|
|
l = [1]
|
|
yield l
|
|
for i in range(length-1):
|
|
nl = [1]
|
|
for j in range(len(l)-1):
|
|
nl.append(l[j]+l[j+1])
|
|
nl.append(1)
|
|
yield nl
|
|
l = nl
|
|
|
|
def prettyprint(l,w):
|
|
s = " ".join(map(str,l))
|
|
indent = int((w - len(s))/2)
|
|
s = (indent * " ") + s
|
|
print(s)
|
|
|
|
length = int(input('Length of pascal triangle: '))
|
|
|
|
for n in pascaltriangle(length):
|
|
prettyprint(n,length*3)
|
|
|