Open In App

Python Program to Print Double Sided Staircase Pattern

Last Updated : 08 Nov, 2025
Comments
Improve
Suggest changes
6 Likes
Like
Report

Given an even number n, the task is to print a double-sided staircase pattern where stars (*) appear on both sides forming a mirror-like structure. The number of stars increases in each step from top to bottom, creating a staircase shape on both sides.

For Example:

Input: n = 10
Output:
* *
* *
* * * *
* * * *
* * * * * *
* * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * *

Let’s explore different methods to print a double sided Staircase pattern in Python.

Using Nested for Loops

This method uses nested loops to control the spaces and stars for each row. It adjusts spacing using one loop and prints stars using another, creating the double-sided staircase effect.

Python
n = 10

for i in range(1, n + 1):
    k = i + 1 if i % 2 != 0 else i

    # Print spaces before stars
    for g in range(k, n):
        print(end=" ")

    # Print stars in each row
    for j in range(k):
        if j == k - 1:
            print(" * ")
        else:
            print(" * ", end=" ")

Output

* *
* *
* * * *
* * * *
* * * * * *
* * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * *

Explanation:

  • for i in range(1, n + 1) controls the total number of rows.
  • k = i + 1 if i % 2 != 0 else i adjusts pattern alignment for odd and even rows.
  • for g in range(k, n) prints spaces before the stars.
  • for j in range(k) prints stars with proper spacing for each step.

Using for Loop

This version keeps the same logic as the nested loop approach but written more compactly. It directly uses string multiplication to print spaces and stars without internal conditionals.

Python
n = 10

for i in range(1, n + 1):
    k = i + 1 if i % 2 != 0 else i
    print(" " * (n - k) + (" * " * k))

Output

* *
* *
* * * *
* * * *
* * * * * *
* * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * *

Explanation:

  • " " * (n - k) adds spaces before stars.
  • " * " * k prints k stars with spacing.

Using while Loop

The same logic can be implemented using a while loop, offering more manual control over iteration. It produces the same double-sided staircase pattern.

Python
n = 10
i = 1

while i <= n:
    k = i + 1 if i % 2 != 0 else i
    print(" " * (n - k) + (" * " * k))
    i += 1

Output

* *
* *
* * * *
* * * *
* * * * * *
* * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * *

Explanation:

  • while i <= n loops through all rows.
  • Uses the same pattern logic as the for loop.
  • Increment i by 1 in each iteration to move down the staircase.

Using List Comprehension

A shorter and more Pythonic approach using list comprehension, though less readable. It achieves the same result in a single line.

Python
n = 10
[print(" " * (n - (i + 1 if i % 2 != 0 else i)) + (" * " * (i + 1 if i % 2 != 0 else i))) for i in range(1, n + 1)]

Output

* *
* *
* * * *
* * * *
* * * * * *
* * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * *

Explanation:

  • The list comprehension iterates through all rows.
  • Calculates k inline using (i + 1 if i % 2 != 0 else i).

Article Tags :

Explore