Part of the series

Several example codes

~1 min read • Updated Oct 7, 2025

Program Overview

This Python program reads the number of rows from the user.
It then prints a pyramid of numbers, where each row contains repeated values equal to the row number.
The spacing ensures the pyramid shape is visually aligned.


Python Code:


rows = int(input("Enter number of rows: "))

for i in range(1, rows + 1):
    print("  " * (rows - i), end="")  # spacing for pyramid alignment
    print((str(i) + " ") * i)

Sample Output for 4 Rows:


      1  
    2 2  
  3 3 3  
4 4 4 4

Step-by-Step Explanation:

- The outer loop runs from 1 to rows
- Each row begins with spaces to align the pyramid
- Then the row number i is printed i times with spacing
- The result is a clean, centered pyramid of repeating numbers


Written & researched by Dr. Shahin Siami