Python Program to Print Pascal Triangle

Write a Python program to print the pascal triangle number pattern using for loop.

from math import factorial

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

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

for i in range(0, rows):
    for j in range(rows - i + 1):
        print(end = ' ')
    for k in range(0, i + 1):
        print(factorial(i)//(factorial(k) * factorial(i - k)), end = ' ')
    print()
Python Program to Print Pascal Triangle

This Python example prints the pascal triangle of numbers using a while loop.

from math import factorial

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

print("====Pascals Triangle Number Pattern====")
i = 0
while(i < rows):
    j = 0
    while(j <= rows - i):
        print(end = ' ')
        j = j + 1
    k = 0
    while(k <= i):
        print(factorial(i)//(factorial(k) * factorial(i - k)), end = ' ')
        k = k + 1
    print()
    i = i + 1
Enter Pascals Triangle Number Pattern Rows = 9
====Pascals Triangle Number Pattern====
          1 
         1 1 
        1 2 1 
       1 3 3 1 
      1 4 6 4 1 
     1 5 10 10 5 1 
    1 6 15 20 15 6 1 
   1 7 21 35 35 21 7 1 
  1 8 28 56 70 56 28 8 1