Python Program to Print Triangle Numbers Pattern

Write a Python program to print triangle numbers pattern using for loop.

rows = int(input("Enter Triangle Numbers Pattern Rows = "))

print("====The Triangle Numbers Pattern====")

for i in range(1, rows + 1):
    for j in range(rows, i, -1):
        print(end = ' ')
    for k in range(1, i + 1):
        print(k, end = ' ')
    print()
Python Program to Print Triangle Numbers Pattern

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

rows = int(input("Enter Triangle Numbers Pattern Rows = "))

print("====The Triangle Numbers Pattern====")
i = 1

while(i <= rows):
    j = rows
    while(j > i):
        print(end = ' ')
        j = j - 1
    k = 1
    while(k <= i):
        print(k, end = ' ')
        k = k + 1
    print()
    i = i + 1
Enter Triangle Numbers Pattern Rows = 9
====The Triangle Numbers 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