Python Pattern Challenge — Day 3
Pattern printing is a fantastic way to improve your Python logic, loops, and problem-solving skills. For Day 3, we're moving from the inverted pattern to a simple centered pyramid pattern.
The Challenge
Can you write a Python program to print this pattern?
* * * * * * * * * * * * * * *
Best code wins!
The goal isn't just to get the output right—try to make your solution clean, readable, and efficient.
Solution 1: Using Nested Loops
This is the most straightforward approach for understanding how spaces and stars work together.
n = 5 for i in range(1, n + 1): # Print spaces for j in range(n - i): print(" ", end=" ") # Print stars for j in range(i): print("*", end=" ") print()
How it works
For every row:
- The number of spaces decreases.
- The number of stars increases.
- end=" " keeps everything on the same line.
- print() moves to the next row.
Solution 2: Using String Multiplication
Python's string operations allow us to solve the same problem with much less code.
n = 5 for i in range(1, n + 1): print(" " * (n - i) + "* " * i)
Here:
" " * (n - i)creates the required indentation, while:
"* " * icreates the stars.
This is a clean and Pythonic solution.
Solution 3: Using join()
Another elegant approach is to generate the stars first and then add the required spaces.
n = 5 for i in range(1, n + 1): stars = " ".join(["*"] * i) print(" " * (n - i) + stars)
This gives you more control over the spacing between individual stars.
What You'll Learn
This challenge helps you practice:
- for loops
- Nested loops
- String multiplication join()
- Spaces and alignment
- Pattern logic
- Breaking a problem into smaller steps
Challenge Yourself
Can you solve this pattern:
*
* * * * * * * * * * * * * *
without using nested loops?
And can you write it in one or two lines of Python?
Drop your solution in the comments and see if you can beat everyone else's code!
Keep Practicing
One pattern may look simple, but solving different patterns consistently can significantly improve your ability to think in terms of loops, conditions, and structured logic.
Follow CLCODING for more Python challenges, coding problems, programming tutorials, and daily learning resources.
Think. Code. Share. Win. 🏆


