Thursday, 24 September 2026
π Python Pattern Challenge — Day 12
Python Developer September 24, 2026 Python Pattern Challenge No comments
π Python Pattern Challenge — Day 12
Pattern printing is a great way to improve your Python logic, nested loops, mathematical thinking, and problem-solving skills. For Day 12, let's move beyond simple star patterns and create a number pattern based on Pascal's Triangle.
The challenge is to generate each row dynamically, where every number is calculated from the values of the previous row.
Today's Challenge
Write a Python program to print:
Best and cleanest code will be rewarded! π
Solution 1 — Using Nested for Loops
n = 6 for i in range(n): num = 1 print(" " * (n - i - 1), end="") for j in range(i + 1): print(num, end=" ") num = num * (i - j) // (j + 1) print()
How it works:
The variable num starts with:
num = 1For every next value, we calculate:
num = num * (i - j) // (j + 1)This formula generates the next value of the current Pascal's Triangle row.
For example:
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
The spacing:
keeps the triangle centered." " * (n - i - 1)
Solution 2 — Using Lists
n = 6 row = [1] for i in range(n): print(" " * (n - i - 1), end="") print(*row) row = [ row[j] + row[j + 1] for j in range(len(row) - 1) ] row = [1] + row + [1]
How it works:
We start with:
row = [1]Then every new row is created by adding neighboring values from the previous row.
For example:
1 3 3 1produces:
1 4 6 4 1because:
1 + 3 = 4Then 1 is added to both ends.
Solution 3 — Using a Function
def pascal(n): row = [1] for i in range(n): print(" " * (n - i - 1), end="") print(*row) row = [1] + [ row[j] + row[j + 1] for j in range(len(row) - 1) ] + [1] pascal(6)
How it works:
Putting the pattern inside a function makes it reusable.
You can easily change:
pascal(6)to:
pascal(10)to generate more rows.
⚡ Short & Clean Code
r = [1] for i in range(6): print(" " * (5-i), *r) r = [1] + [r[j] + r[j+1] for j in range(i)] + [1]
π₯ This compact version generates the same Pascal's Triangle pattern using a single main loop.
π Challenge Yourself
Can you modify this pattern:
- Generate 10 or 15 rows?
- Create Pascal's Triangle using only nested loops?
- Take the number of rows using input()?
- Print the triangle upside down?
- Replace the numbers with *?
- Calculate the sum of every row?
- Find the largest number in the generated triangle?
Drop your solution below! π
12 Days. 12 Patterns. Stronger Python Logic. ππ₯
Learn • Practice • Grow with CLCODING
Wednesday, 23 September 2026
Python Turtle: A Heart Made of Code
Python Developer September 23, 2026 Python Library No comments
Code:
import turtle
import math
import time
screen = turtle.Screen()
screen.setup(700, 700)
screen.bgcolor("#03000a")
screen.tracer(0)
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
colors = ["#ff1744", "#ff4081", "#d500f9", "#7c4dff", "#00e5ff"]
# ❤️ Neon Heart
for i in range(360):
a = math.radians(i)
x = 16 * math.sin(a) ** 3
y = (
13 * math.cos(a)
- 5 * math.cos(2*a)
- 2 * math.cos(3*a)
- math.cos(4*a)
)
scale = 15
t.penup()
t.goto(0, 0)
t.pendown()
t.color(colors[i % len(colors)])
t.goto(x * scale, y * scale)
t.dot(3 + i % 3)
screen.update()
time.sleep(0.02)
# ✨ Glowing Center
for r in range(25, 2, -3):
t.penup()
t.goto(0, -r)
t.dot(r, colors[r % len(colors)])
screen.update()
time.sleep(0.06)
# ⭐ Small Sparkles
for i in range(25):
angle = i * 137.5
radius = 230 + (i % 4) * 15
x = radius * math.cos(math.radians(angle))
y = radius * math.sin(math.radians(angle))
t.penup()
t.goto(x, y)
t.dot(2 + i % 3, colors[i % len(colors)])
screen.update()
time.sleep(0.03)
turtle.done()
Explanation:
Popular Posts
-
GitHub is more than just a platform for storing code. It's a place to learn from experienced developers, explore open-source projects,...
-
In a world increasingly shaped by data, the demand for professionals who can make sense of it has never been higher. Businesses, governmen...
-
What you'll learn Understand the cybersecurity landscape and learn core concepts foundational to security, compliance, and identity so...
-
Hands-on Python Tutorial by Dr. Andrew N. Harrington is a practical learning resource designed to introduce beginners to programming thr...
-
π Stanford Code in Place 2026: Learn Python for Free Stanford Code in Place 2026 is a popular international programming course from Stan...
-
In the fast-paced world of software development , mastering version control is essential. Git and GitHub have become industry standards, ...
-
Theoretical Computer Science (TCS) is the mathematical foundation of computing. Instead of focusing only on how to write programs, it ask...
-
Physics-based Deep Learning: Combining Deep Learning with Physical Simulations Physics-based Deep Learning (PBDL) is a practical learning...
-
Linear Algebra Done Right by Sheldon Axler is a well-known textbook that presents linear algebra from a more conceptual and proof-orient...
-
Every data scientist, analyst, and business intelligence professional needs one foundational skill above almost all others: the ability to...
