Python Program to Print Double Sided Staircase Pattern (original) (raw)

Last Updated : 8 Nov, 2025

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:

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:

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:

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: