๐ Python Pattern Challenge — Day 30 | Number Mirror Pyramid
Welcome to Day 30 of the Python Pattern Challenge! ๐
We've completed 29 days of pattern-printing practice, and today we're creating a beautiful Number Mirror Pyramid. This pattern increases from 1 to 5 and then decreases back to 1, forming a symmetrical diamond.
It's a great exercise for improving your Python logic, nested loops, number sequences, and pattern-building skills.
๐ฏ Today's Challenge
Write a Python program to print exactly this pattern:
Can you solve this challenge using the cleanest Python code? ๐
๐ป Solution 1 — Using Nested for Loops
n = 5 for i in list(range(1, n + 1)) + list(range(n - 1, 0, -1)): print(" " * (n - i), end="") for j in range(1, i + 1): print(j, end=" ") for j in range(i - 1, 0, -1): print(j, end=" ") print()
๐ง How It Works
1. Controlling the rows
for i in list(range(1, n + 1)) + list(range(n - 1, 0, -1)):This creates the row sequence 1, 2, 3, 4, 5, 4, 3, 2, 1. The first half expands the pattern, while the second half shrinks it.
2. Adding spaces
print(" " * (n - i), end="")This adds leading spaces to center each row and create the diamond shape.
3. Printing increasing numbers
for j in range(1, i + 1):This prints numbers from 1 up to the current row number.
For example, when i = 4, it prints:
1 2 3 44. Printing decreasing numbers
for j in range(i - 1, 0, -1):
print(j, end=" ")
This prints the numbers in reverse order without repeating the largest number.
The result is:
1 2 3 4 3 2 1⚡ Solution 2 — Using Lists
n = 5 for i in range(1, n + 1): row = list(range(1, i + 1)) row += list(range(i - 1, 0, -1)) print(" " * (n - i) + " ".join(map(str, row))) for i in range(n - 1, 0, -1): row = list(range(1, i + 1)) row += list(range(i - 1, 0, -1)) print(" " * (n - i) + " ".join(map(str, row)))
This version builds each row as a list and joins its numbers into a string before printing.
๐ Challenge Yourself
Can you modify today's pattern?
Increase the maximum number from 5 to 7.
Create the same pattern using a while loop.
Replace numbers with alphabets.
Print the pattern upside down.
Create a similar diamond using * symbols.
Take the maximum number from the user using input().
Share your solution in the comments! ๐
30 Days. 30 Patterns. Stronger Python Logic. ๐๐ฅ
Learn • Practice • Grow with CLCODING ๐ป


.png)

.png)


