Tuesday, 20 October 2026

๐Ÿ Python Pattern Challenge — Day 31

 


๐Ÿ Python Pattern Challenge — Day 31 | Hollow Diamond Star Pattern

Welcome to Day 31 of the Python Pattern Challenge! ๐Ÿš€

Today, we're creating a beautiful Hollow Diamond Star Pattern using Python. This pattern combines stars and spaces to form a diamond shape with an empty center.

It's a great way to practice nested loops, conditional statements, spacing, and logical thinking while creating an attractive design using just a few lines of Python code.

๐ŸŽฏ Today's Challenge

Write a Python program to print exactly this pattern:


๐Ÿ’ป Solution 1 — Using Nested for Loops

n = 4 for i in range(1, n + 1): for j in range(n - i): print(" ", end=" ") for j in range(2 * i - 1): print("*", end=" ") print() for i in range(n - 1, 0, -1): for j in range(n - i): print(" ", end=" ") for j in range(2 * i - 1): print("*", end=" ") print()









This code creates a filled diamond pattern. To make it hollow, we need to add conditions that print stars only along the boundary and spaces inside.

๐Ÿง  Solution 2 — Creating a Hollow Diamond

n = 5

for i in range(-n + 1, n): for j in range(-n + 1, n): if abs(i) + abs(j) == n - 1: print("*", end=" ") else: print(" ", end=" ") print()






How It Works

1. Controlling the rows and columns

for i in range(-n + 1, n): 
    for j in range(-n + 1, n):

The outer loop controls the rows, while the inner loop controls the positions within each row.

2. Checking the diamond boundary

if abs(i) + abs(j) == n - 1:

The abs() function returns the absolute value of a number. This condition identifies positions along the diamond's boundary.

3. Printing stars and spaces

print("*", end=" ")

Stars appear on the boundary, while spaces are printed inside the shape.

⚡ What You Learn Today

  • Using nested for loops

  • Applying conditional statements

  • Understanding the abs() function

  • Controlling star positions with mathematical logic

  • Creating symmetrical patterns using Python

๐Ÿš€ Challenge Yourself

Can you modify today's pattern?

  • Increase the diamond size.

  • Replace * with # or @.

  • Create a filled diamond.

  • Print the pattern using a while loop.

  • Take the size as user input.

  • Create a hollow square using similar logic.

Share your solution in the comments! ๐Ÿ‘‡

31 Days. 31 Patterns. Stronger Python Logic. ๐Ÿ๐Ÿ”ฅ

Learn • Practice • Grow with CLCODING ๐Ÿ’ป

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (352) Android (25) AngularJS (1) API (1) Assembly Language (2) aws (31) Azure (12) BI (10) book (1) Books (359) Bootcamp (16) C (78) C# (12) C++ (83) cloud (1) Course (95) Coursera (306) Cybersecurity (36) data (10) Data Analysis (47) Data Analytics (31) data management (16) Data Science (437) Data Strucures (20) Deep Learning (223) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (9) Excel (24) Finance (13) flask (4) flutter (1) FPL (17) Gadgets (1) Generative AI (79) 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 (410) Meta (24) MICHIGAN (5) microsoft (13) Nvidia (8) Pandas (16) PHP (20) Projects (35) Python (1388) Python Coding Challenge (1281) Python Library (26) Python Mathematics (22) Python Mistakes (51) Python Pattern Challenge (28) python quixz (1) Python Quiz (663) Python Tips (114) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (21) SQL (55) Udemy (23) UX Research (1) web application (11) Web development (9) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)