๐ Python Pattern Challenge — Day 28 | Number Mirror Pyramid
Welcome to Day 28 of the Python Pattern Challenge! ๐
Today, we're creating a beautiful Number Mirror Pyramid using simple number sequences. This pattern starts with 1 in the center, expands on both sides, and then shrinks back to 1, creating a symmetrical design.
This challenge is perfect for practicing nested loops, number sequences, spacing, and logical thinking.
๐ฏ Today's Challenge
Write a Python program to print exactly this pattern:
Can you create this pattern using Python loops? ๐
๐ป Solution 1 — Using Nested for Loops
n = 4 for i in range(1, n + 1): print(" " * (n - i), end="") for j in range(i, 0, -1): print(j, end=" ") for j in range(2, i + 1): print(j, end=" ") print() for i in range(n - 1, 0, -1): print(" " * (n - i), end="") for j in range(i, 0, -1): print(j, end=" ") for j in range(2, i + 1): print(j, end=" ") print()
๐ง How It Works
1. Creating the upper half
for i in range(1, n + 1):This loop generates the first four rows, increasing the pyramid's width with each row.
2. Printing decreasing numbers
for j in range(i, 0, -1):This loop prints numbers in descending order toward the center.
For example, when i = 4, it prints:
4 3 2 13. Printing increasing numbers
for j in range(2, i + 1):This loop prints the numbers in ascending order after 1, creating the mirror effect:
4 3 2 1 2 3 44. Creating the lower half
The second outer loop repeats the same logic in reverse order, shrinking the pyramid until only 1 remains.
⚡ Solution 2 — Using a List
n = 4This version combines the upper and lower row sequences into one loop.
๐ Challenge Yourself
Can you modify today's pattern?
Increase the pyramid to 6 rows.
Create the same pattern using a while loop.
Replace numbers with alphabets.
Print the mirror pyramid upside down.
Use a different number in the center.
Create your own symmetrical number pattern.
Share your solution in the comments! ๐
28 Days. 28 Patterns. Stronger Python Logic. ๐๐ฅ
Learn • Practice • Grow with CLCODING ๐ป



0 Comments:
Post a Comment