๐ Python Pattern Challenge — Day 38 | Hollow Number Diamond
Welcome to Day 38 of the Python Pattern Challenge! ๐
Today, we're creating a beautiful Hollow Number Diamond Pattern using Python. This pattern combines increasing and decreasing number sequences with carefully placed spaces to form a diamond with an open center.
It's a great way to practice loops, number sequences, spacing, and logical thinking while improving your Python programming skills.
๐ฏ 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="") if i < n: print(" ".join(map(str, range(1, i + 1))), end=" ") if i > 1: print(" " * (i - 2), end="") print(" ".join(map(str, range(i, 0, -1)))) else: print() else: print(" ".join(map(str, range(1, n + 1))), *range(n - 1, 0, -1)) for i in range(n - 1, 0, -1): print(" " * (n - i), end="") print(" ".join(map(str, range(1, i + 1))), *range(i - 1, 0, -1))
๐ง How It Works
1. Controlling the rows
The outer for loops create the upper and lower sections of the diamond.
2. Managing the spacing
Leading spaces move each row toward the center, while additional spaces create the hollow section.
3. Printing increasing numbers
The range(1, i + 1) sequence prints numbers in ascending order.
4. Printing decreasing numbers
The reverse sequence prints numbers in descending order, creating the mirrored appearance.
5. Completing the diamond
The second loop reverses the row sizes to complete the lower half of the design.
๐ Challenge Yourself
Increase the diamond size to seven rows.
Replace numbers with alphabets.
Create a completely hollow diamond.
Try solving the pattern using nested loops.
Take the size as input from the user.
Practice the pattern, experiment with the spacing, and challenge yourself to recreate it without looking at the solution!
38 Days. 38 Patterns. Stronger Python Logic. ๐๐ฅ
Learn • Practice • Grow with CLCODING



.png)

.png)


.png)


