DEV Community

Cover image for Day 15: Pascal's Triangle
Matt Ryan
Matt Ryan

Posted on

Day 15: Pascal's Triangle

Pascal's Triangle is a number pattern. Each number is the numbers directly above it added together.

Alt Text

row = int(input("Enter number of rows: "))

space = 36
a = [0] * 20 


for i in range(row):

    for spi in range(1,space+1):
        print(" ", end="")

    a[i] = 1

    for j in range(i+1):
        print('%6d' %(a[j]), end = "")

    for j in range(i,0,-1):
        a[j] = a[j] + a[j-1]

    space = space - 3

    print()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)