Wednesday, 30 September 2026
Tuesday, 29 September 2026
๐ Python Pattern Challenge — Day 16
Python Developer September 29, 2026 Python Pattern Challenge No comments
๐ Python Pattern Challenge — Day 16
Pattern printing is a great way to improve your Python loops, conditions, spacing, and logical thinking. For Day 16, let's create a Hollow Star Diamond Pattern ⭐.
Unlike a filled diamond, this pattern keeps the center empty and uses stars only along the outer shape. It is a good exercise for understanding nested loops, spaces, and boundary conditions.
Today's Challenge
Write a Python program to print:
Best and cleanest code will be rewarded! ๐
Solution 1 — Using Nested Loops
n = 6 for i in range(n): spaces = n - i - 1 gap = 2 * i - 1 if i == 0: print(" " * (spaces * 2) + "*") else: print( " " * (spaces * 2) + "* *" + " " * (gap * 2) + "* *" ) for i in range(n - 2, -1, -1): spaces = n - i - 1 gap = 2 * i - 1 if i == 0: print(" " * (spaces * 2) + "*") else: print( " " * (spaces * 2) + "* *" + " " * (gap * 2) + "* *" )
How it works
The pattern has two parts:
Upper half:
Lower half:
* * * * * * * * * * * * * * *
The number of spaces between the stars increases toward the center and then decreases again.
Solution 2 — Using a Pattern Formula
n = 6 for i in list(range(n)) + list(range(n - 2, -1, -1)): if i == 0: print(" " * (2 * (n - 1)) + "*") else: left = " " * (2 * (n - i - 1)) middle = " " * (2 * i - 1) print(left + "* *" + middle + "* *")
How it works
Instead of writing two separate loops, we create one sequence:
list(range(n)) + list(range(n - 2, -1, -1))which produces:
0 1 2 3 4 5 4 3 2 1 0This controls the expansion and contraction of the diamond.
Solution 3 — Using a Function
def hollow_diamond(n): for i in list(range(n)) + list(range(n - 2, -1, -1)): if i == 0: print(" " * (2 * (n - 1)) + "*") else: left = " " * (2 * (n - i - 1)) middle = " " * (2 * i - 1) print(left + "* *" + middle + "* *") hollow_diamond(6)
Now you can change:
hollow_diamond(6)to:
hollow_diamond(8)to experiment with a larger pattern.
⚡ Short & Clean Code
n = 6 for i in list(range(n)) + list(range(n-2, -1, -1)): if i == 0: print(" " * (2*n-2) + "*") else: print(" "*(2*(n-i-1)) + "* *" + " "*(2*i-1) + "* *")
๐ฅ A compact solution using just one main loop.
๐ Challenge Yourself
Can you modify this pattern:
- Make the diamond larger?
- Create a double hollow diamond?
- Replace * with another symbol?
- Create the same pattern using a while loop?
- Remove the extra spaces between the outer stars?
- Create a filled version of this pattern?
Drop your solution below! ๐
16 Days. 16 Patterns. Stronger Python Logic. ๐๐ฅ
✨ Python TurtleThe Crystal Flower
Python Developer September 29, 2026 Python Library No comments
Code:
import turtle
import time
screen = turtle.Screen()
screen.setup(700, 700)
screen.bgcolor("#02030a")
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
t.width(2)
colors = [
"#ff2d75", "#d500f9",
"#7c4dff", "#00e5ff",
"#00ff9d", "#ffe600"
]
# ๐ธ Petal diamonds
for i in range(12):
t.color(colors[i % len(colors)])
t.fillcolor(colors[i % len(colors)])
t.penup()
t.goto(0, 0)
t.setheading(i * 30)
t.pendown()
t.begin_fill()
for _ in range(2):
t.forward(170)
t.left(60)
t.forward(70)
t.left(120)
t.end_fill()
screen.update()
time.sleep(0.12)
# ✨ Inner petals
for i in range(12):
t.color("#ffffff")
t.penup()
t.goto(0, 0)
t.setheading(i * 30 + 15)
t.pendown()
for _ in range(2):
t.forward(90)
t.left(60)
t.forward(35)
t.left(120)
screen.update()
time.sleep(0.08)
# ๐ Center
t.penup()
t.goto(0, -20)
t.dot(40, "#ffe600")
t.goto(0, -8)
t.dot(15, "white")
turtle.done()
Explanation:

Popular Posts
-
Deep Learning Methods of Mathematical Physics: Volume I – A Comprehensive Guide to AI for Direct and Inverse Problems Introduction Artific...
-
Python Illustrated: Not Another Boring Python Book — Learn Programming the Fun Way Introduction Learning Python can be exciting, but begin...
-
Python Foundations to Interview Mastery 15 Days • 4 Core Phases • Hands-On Coding • Interview Preparation A focused 15-day bootcamp design...
-
Introduction In today’s digital world, many jobs require repetitive, time-consuming computer tasks: renaming files, updating spreadsheets,...
-
Machine learning has become one of the most influential fields in computer science, powering technologies such as recommendation systems, ...
-
Code Explanation: 1. ๐ง Define the Generator Function def gen(): This creates a function named gen. Because the function contains yield, i...
-
Microsoft Power BI Data Analyst Professional Certificate What you'll learn Learn to use Power BI to connect to data sources and transf...
-
Statistics and Probability: Fundamentals and Practical Applications – A Complete Guide for Mathematics, Data Science, and Machine Learning...
-
Microsoft Python Development Professional Certificate: A Complete Guide for 2025 Python is the go-to language for web development, automat...
-
Theoretical Computer Science (TCS) is the mathematical foundation of computing. Instead of focusing only on how to write programs, it ask...
