⚡ TL;DR
Print the ladder star pattern in Python with working code and output. Working implementation, sample run, and complexity analysis included.
The Ladder Star pattern is a classic loop exercise. Here’s the complete implementation in Python with working code and output.
Pattern to Print
* *
*****
* *
*****
* *Implementation
def ladder_star(n):
for i in range(1, n + 1):
if i % 2 == 0:
print("*" * n)
else:
print("*" + " " * (n - 2) + "*")
ladder_star(5)Output
* *
*****
* *
*****
* *How It Works
Odd rows draw the two rails — a star at each end with n−2 spaces between — and even rows draw a full rung across the width. One parity check per row is all it takes to alternate rails and rungs.
Practice Variations
- Try printing the pattern with a different character (e.g.,
#or+) - Modify the code to accept the pattern size as user input
- Combine this pattern with its inverse to create a more complex shape
Complexity
- Time: O(n²) — the grid or line count grows quadratically
- Space: O(n²) — the grid is stored before printing
FAQ
How do you print the Ladder Star pattern in Python?
Use nested loops: the outer loop walks through the rows while the inner loop prints the characters or values for each row. The complete Python implementation with expected output is shown in the sections above.
What is the time complexity of the Ladder Star pattern in Python?
The time complexity is O(n²) and the space complexity is O(n²), since the pattern is built on a grid that is filled first and then printed row by row.
Happy coding!

Written by Mihir Pipermitwala
Senior Full Stack Consultant & Mobile Engineering Specialist building user-focused applications in healthcare with Flutter, Dart and React Native. I write about what I actually build and test — every tutorial here comes from real project work.
More about Mihir →