Thursday, 15 October 2026

๐Ÿ Python Pattern Challenge — Day 28

 



๐Ÿ 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):
     print(j, end=" ")

This loop prints numbers in descending order toward the center.

For example, when i = 4, it prints:

4 3 2 1

3. Printing increasing numbers

for j in range(2, i + 1): 
    print(j, end=" ")

This loop prints the numbers in ascending order after 1, creating the mirror effect:

4 3 2 1 2 3 4

4. 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 = 4
 for i in list(range(1, n + 1)) + list(range(n - 1, 0, -1)): 
left = list(range(i, 0, -1)) 
right = list(range(2, i + 1)) 
print(" " * (n - i) + " ".join(map(str, left + right)))

This 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

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (363) Android (25) AngularJS (1) API (2) Assembly Language (2) aws (31) Azure (12) BI (10) book (1) Books (359) Bootcamp (20) C (78) C# (12) C++ (83) cloud (1) Course (97) Coursera (307) Cybersecurity (38) data (11) Data Analysis (48) Data Analytics (32) data management (17) Data Science (449) Data Strucures (22) Deep Learning (229) Django (17) Downloads (3) edx (21) Engineering (15) Euron (30) Events (9) Excel (24) Finance (13) flask (4) flutter (1) FPL (17) Gadgets (2) Generative AI (80) Git (14) Google (55) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (43) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (421) Meta (24) MICHIGAN (5) microsoft (13) Nvidia (8) Pandas (16) PHP (20) Projects (36) Python (1417) Python Bug (1) Python Coding Challenge (1321) Python Library (29) Python Mathematics (25) Python Mistakes (51) Python Pattern Challenge (51) Python Quiz (704) Python Tips (115) Python Turtle (3) Questions (3) R (72) React (7) Scripting (3) security (5) Selenium Webdriver (4) Software (21) SQL (57) Udemy (24) UX Research (1) web application (11) Web development (9) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)