Friday, 2 October 2026
Python Coding challenge - Day 1271| What is the output of the following Python Code?
Python Developer October 02, 2026 Python Coding Challenge No comments
Code Explanation:
100 Python Programs for Beginner with explanation
Python Coding challenge - Day 1270| What is the output of the following Python Code?
Python Developer October 02, 2026 Python Coding Challenge No comments
Code Explanation:
Book: 400 Days Python Coding Challenges with Explanation
Thursday, 1 October 2026
๐ Python Pattern Challenge — Day 17
Python Developer October 01, 2026 Python Library No comments
๐ Python Pattern Challenge — Day 17
Pattern printing is a great way to improve your Python loops, spacing, nested loops, and logical thinking. For Day 17, let's create a Hollow Star Diamond Pattern ⭐.
This pattern looks like a diamond from the outside, but the center remains empty. The challenge is to control the left spaces, stars, and inner spaces correctly.
Today's Challenge
Write a Python program to print:
Best and cleanest code will be rewarded! ๐
Solution 1 — Using Nested for Loops
n = 4 # Upper part for i in range(1, n + 1): print(" " * (n - i), end="") for j in range(2 * i - 1): print("*", end=" ") print() # Middle hollow part for i in range(3): print("* *", end=" ") print(" " * 3, end="") print("* *") # Lower part for i in range(n - 1, 0, -1): print(" " * (n - i), end="") for j in range(2 * i - 1): print("*", end=" ") print()
How it works
The first loop creates the growing upper section:
* * * * * * * * * * * * * * * * Then the middle section keeps the center empty: * * * * * * * * * * * *Finally, the last loop creates the decreasing lower section: * * * * * * * * *
Solution 2 — Using String Multiplication
n = 4 for i in range(1, n + 1): print(" " * (n - i) + "* " * (2 * i - 1)) for i in range(3): print("* *" + " " * 3 + "* *") for i in range(n - 1, 0, -1): print(" " * (n - i) + "* " * (2 * i - 1))
Here:
"* " * (2 * i - 1)controls the number of stars in the upper and lower sections.
And:
" " * 3creates the empty space in the center.
Solution 3 — Using a Function
def star_pattern(n): for i in range(1, n + 1): print(" " * (n - i) + "* " * (2 * i - 1)) for _ in range(3): print("* *" + " " * 3 + "* *") for i in range(n - 1, 0, -1): print(" " * (n - i) + "* " * (2 * i - 1)) star_pattern(4)
Using a function makes the pattern reusable and allows you to experiment with different sizes.
⚡ Short & Clean Code
n = 4 for i in range(1, n + 1): print(" " * (n-i) + "* " * (2*i-1)) for _ in range(3): print("* *" + " " * 3 + "* *") for i in range(n-1, 0, -1): print(" " * (n-i) + "* " * (2*i-1))
๐ฅ This version keeps the logic simple while producing the complete pattern.
๐ Challenge Yourself
Can you modify this pattern:
- Make the pattern larger?
- Take the size using input()?
- Create the same pattern using a while loop?
- Make the center gap wider?
- Replace * with another symbol?
- Create a completely hollow version?
Drop your solution below! ๐
17 Days. 17 Patterns. Stronger Python Logic. ๐๐ฅ
Learn • Practice • Grow with CLCODING ๐
Python for Geography & Geospatial Analysis
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...
