๐ Python Pattern Challenge — Day 56 | Number Diamond Pyramid Pattern
Welcome to Day 56 of the Python Pattern Challenge! ๐
Today, we're creating a beautiful Number Diamond Pyramid Pattern using Python.
This pattern starts with the number 1 at the top and gradually expands toward the center. Each row contains increasing numbers followed by decreasing numbers, creating a symmetrical diamond shape.
After reaching the middle row, the pattern reverses and gradually shrinks until it ends with 1.
This challenge is perfect for improving your understanding of nested loops, number sequences, spacing, and mathematical logic.
๐ฏ Today's Challenge
Write a Python program to print exactly the following pattern:
๐ป Python Solution
n = 5 for i in range(1, n + 1): row = list(range(i, 2 * i)) row += list(range(2 * i - 2, i - 1, -1)) print(" " * (n - i) + " ".join(map(str, row))) for i in range(n - 1, 0, -1): row = list(range(i, 2 * i)) row += list(range(2 * i - 2, i - 1, -1)) print(" " * (n - i) + " ".join(map(str, row)))
๐ง Understanding the Logic
1. Define the pattern size
n = 5
This variable determines the maximum number of levels in the upper half of the diamond.
2. Generate increasing numbers
row = list(range(i, 2 * i))This generates an increasing sequence of numbers for each row.
3. Generate decreasing numbers
row += list(range(2 * i - 2, i - 1, -1))This adds the decreasing sequence, creating a symmetrical number arrangement.
4. Manage the spacing
" " * (n - i)This adds leading spaces before each row to create the diamond shape.
5. Print the upper half
for i in range(1, n + 1):The loop gradually increases the number of elements until it reaches the widest row.
6. Print the lower half
for i in range(n - 1, 0, -1):The reverse loop recreates the same structure in decreasing order, completing the diamond.
๐ Challenge Yourself
Increase the maximum number from 9 to 11.
Replace numbers with alphabets.
Create an inverted number diamond.
Try generating the pattern using nested loops.
Experiment with different number sequences.
๐ก What Will You Learn?
By completing this challenge, you will practice:
Python for loops
range() function
List creation and concatenation
Number sequences
map() function
String formatting
Symmetrical pattern logic
๐ฏ Final Thoughts
Number patterns are an excellent way to improve your programming logic. They teach you how to combine mathematical sequences, loops, and spacing to create beautiful designs.
Keep practicing and challenge yourself with more complex Python patterns!
56 Days. 56 Patterns. Stronger Python Logic! ๐๐ฅ
Learn • Practice • Grow with CLCODING


.png)

.png)



