Python Program for 1-121-12321 Triangle (Pyramid) Pattern

This program generates 1-121-12321-1234321 numeric triangle (pyramid) pattern up to n number of lines in Python programming language.

In this program we first read number of rows from user and set outer loop i for number of lines. Generating 1-121-12321 pattern requires setup for space pattern, increasing number pattern & decreasing number pattern which are set by inner loop j. See program below:

Python Source Code: 1-121-12321 Triangle


# Pattern 1-121-12321 pyramid pattern

# Reading number of rows
row = int(input('Enter how many lines? '))

# Generating pattern
for i in range(1,row+1):
    
    # for space
    for j in range(1, row+1-i):
        print(' ', end='')
    
    # for increasing pattern
    for j in range(1,i+1):
        print(j, end='')
    
    # for decreasing pattern 
    for j in range(i-1,0,-1):
        print(j, end='')
    
    # Moving to next line
    print()

Python Output: 1-212-32123 Pattern

Enter how many lines? 9

        1
       121
      12321
     1234321
    123454321
   12345654321
  1234567654321
 123456787654321
12345678987654321