๐ Python Pattern Challenge — Day 52 | Hourglass Diamond Star Pattern
Welcome to Day 52 of the Python Pattern Challenge! ๐
Today, we're creating a beautiful Hourglass Diamond Star Pattern using Python.
This pattern combines three diagonal star arrangements that gradually move toward the center, followed by a complete horizontal line of stars. The lower section repeats the same arrangement in reverse order, creating a symmetrical geometric design.
It looks simple, but generating this pattern requires a good understanding of character positions, loops, spacing, and symmetry.
Let's build it step by step!
๐ฏ Today's Challenge
Write a Python program to print exactly the following pattern:
๐ป Python Solution
n = 5 width = 13 for i in range(n): row = [" "] * width for j in [i, 6, 12 - i]: row[j] = "*" print("".join(row)) print("*" * width) for i in range(n - 1, -1, -1): row = [" "] * width for j in [i, 6, 12 - i]: row[j] = "*" print("".join(row))
๐ง Understanding the Logic
1. Define the pattern dimensions
n = 5Here, n controls the number of diagonal rows, while width defines the total character positions.
2. Create an empty row
row = [" "] * widthThis creates a row containing 13 spaces. Stars will be placed at selected positions.
3. Calculate star positions
for j in [i, 6, 12 - i]:This is the main logic of the pattern.
i moves the left diagonal toward the center.
6 keeps the middle star fixed.
12 - i moves the right diagonal toward the center.
4. Print the upper section
for i in range(n):The loop gradually moves the diagonal stars toward the center.
5. Print the horizontal center
print("*" * width)This creates the complete horizontal line of 13 stars.
6. Generate the lower section
for i in range(n - 1, -1, -1):The reverse loop moves the diagonal stars outward again, completing the symmetrical pattern.
๐ Challenge Yourself
Increase the pattern size.
Replace stars with numbers or alphabets.
Create the same design using nested loops.
Experiment with different center positions.
Try creating an hourglass pattern without the middle horizontal line.
๐ก What You Will Learn
By completing this challenge, you will practice:
Python for loops
List manipulation
String joining
Index positioning
Nested iteration
Symmetrical pattern design
๐ฏ Final Thoughts
Python pattern printing is not just about displaying stars. It teaches you how to think logically, calculate positions, control spacing, and understand how loops work together.
The more patterns you solve, the stronger your programming fundamentals become.
53 Days. 53 Patterns. Stronger Python Logic! ๐๐ฅ
Keep Learning. Keep Practicing. Keep Coding!
Learn • Practice • Grow with CLCODING



0 Comments:
Post a Comment