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
-
Calculus by Gilbert Strang: Understanding the Mathematics of Change Introduction Calculus is one of the most important branches of mathema...
-
Introduction Python is one of the most widely used programming languages, powering web development, automation, data analysis, artificial in...
-
In statistics, data science, machine learning, and artificial intelligence, we often have to make decisions when we do not have complete i...
-
Python continues to evolve, making programming more expressive and improving the experience for developers. On October 9, 2026, Python 3.1...
-
Python Illustrated: Not Another Boring Python Book — Learn Programming the Fun Way Introduction Learning Python can be exciting, but begin...
-
Microsoft Python Development Professional Certificate: A Complete Guide for 2025 Python is the go-to language for web development, automat...
-
Introduction Linear algebra is one of the most important branches of mathematics for computer science, engineering, data science, and arti...
-
Introduction to Machine Learning by Laurent Younes: A Mathematical Guide to Modern Machine Learning Introduction Machine learning is one of ...
-
Artificial Intelligence (AI) is no longer confined to research labs — it’s now central to business innovation, technology strategy, and ev...
-
Introduction In a world where being able to build software quickly and solve real-world problems is highly valued, simply knowing programm...
