Python Program to Print Left Pascals Number Triangle

Write a Python program to print left pascals number triangle using for loop.

rows = int(input("Enter Left Pascals Number Triangle Pattern Rows = "))

print("====Left Pascals Number Triangle Pattern====")

for i in range(1, rows + 1):
    for j in range(i, rows):
        print(end = '  ')
    for k in range(1, i + 1):
        print(k, end = ' ')
    print()

for i in range(rows, 0, -1):
    for j in range(i, rows + 1):
        print(end = '  ')
    for k in range(1, i):
        print(k, end = ' ')
    print()
Python Program to Print Left Pascals Number Triangle

This Python example prints the left pascals number triangle using a while loop.

rows = int(input("Enter Left Pascals Number Triangle Pattern Rows = "))

print("====Left Pascals Number Triangle Pattern====")
i = 1
while(i <= rows):

    j = i
    while(j < rows):
        print(end = '  ')
        j = j + 1

    k = 1
    while(k <= i):
        print(k, end = ' ')
        k = k + 1
    print()
    i = i + 1

i = rows
while(i >= 1):
    j = i
    while(j <= rows):
        print(end = '  ')
        j = j + 1

    k = 1
    while(k < i):
        print(k, end = ' ')
        k = k + 1
    print()
    i = i - 1
Enter Left Pascals Number Triangle Pattern Rows = 9
====Left Pascals Number Triangle Pattern====
                1 
              1 2 
            1 2 3 
          1 2 3 4 
        1 2 3 4 5 
      1 2 3 4 5 6 
    1 2 3 4 5 6 7 
  1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9 
  1 2 3 4 5 6 7 8 
    1 2 3 4 5 6 7 
      1 2 3 4 5 6 
        1 2 3 4 5 
          1 2 3 4 
            1 2 3 
              1 2 
                1 

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.