Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
GreenGeeks Web Hosting - Faster, Scalable & Eco-Friendly

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,917 questions

11,028 answers

573 users

How to calculate and print the Pascal triangle in Python

1 Answer

0 votes
rows = 6
array = []

for i in range(rows):
    array.append([])
    array[i].append(1)
    for j in range(1, i):
        array[i].append(array[i-1][j-1]+array[i-1][j])
    if rows != 0:
        array[i].append(1)
for i in range(rows):
    print("   "*(rows-i), end=" ", sep=" ")
    for j in range(0, i+1):
        print('{0:5}'.format(array[i][j]), end=" ", sep=" ")
    print()


'''
run:

                       1
                    1     1
                 1     2     1
              1     3     3     1
           1     4     6     4     1
        1     5    10    10     5     1


'''

 




answered Dec 17, 2017 by avibootz
...