๐ Python Pattern Challenge — Day 37 | Number Diamond Pattern
Welcome to Day 37 of the Python Pattern Challenge! ๐
Today, we're creating a beautiful Number Diamond Pattern using Python. This pattern combines increasing and decreasing number sequences to form a symmetrical diamond shape.
Each row follows a simple numerical sequence, making this challenge perfect for practicing loops, number manipulation, spacing, and logical thinking.
๐ฏ Today's Challenge
Write a Python program to print the following pattern:
๐ป Python Solution
n = 5 for i in range(1, n + 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() for i in 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. Creating the upper half
The first for loop increases the row size from 1 to 5, building the upper half of the diamond.
2. Printing increasing numbers
The inner loop prints numbers from 1 up to the current row number.
3. Printing decreasing numbers
The second inner loop prints the numbers in reverse order, creating the mirrored sequence.
4. Controlling the spacing
The expression " " * (n - i) adds leading spaces to align the rows and create the diamond shape.
5. Creating the lower half
The second outer loop reverses the process, decreasing the row size until only 1 remains.
๐ Challenge Yourself
Increase the diamond size to 7 rows.
Replace numbers with alphabets.
Create a hollow number diamond.
Try using a while loop instead of a for loop.
Take the diamond size as input from the user.
Pattern printing helps develop problem-solving skills and builds a strong foundation in Python programming.
37 Days. 37 Patterns. Stronger Python Logic. ๐๐ฅ
Learn • Practice • Grow with CLCODING
.png)


.png)




