Pascal triangle

# Pascal triangle - 5 lines

L = [[1],[1,1]]
lno = 2

while(lno < 5):
tmp = [1]
i = 1
while(i<lno):
ele = L[lno-1][i-1]+L[lno-1][i]
tmp.append(ele)
i+=1
tmp.append(1)
lno+=1
L.append(tmp)


for ele in L:
print(" "*lno, end=" ")
for e in ele:
print(e, end= " ")
lno-=1
print()

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu