DEV Community

loading...
Cover image for Day 15: Pascal's Triangle

Day 15: Pascal's Triangle

mattryanmtl profile image Matt Ryan ・1 min read

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

Discussion (0)

Forem Open with the Forem app