Thursday, 8 October 2026
Python Coding Challenge - Question with Answer (ID 081026)
Explanation:
Wednesday, 7 October 2026
๐ Python Pattern Challenge — Day 21
Python Developer October 07, 2026 Python Pattern Challenge No comments
๐ Python Pattern Challenge — Day 21
Pattern printing is a great way to strengthen your Python loops, repetition, and logical thinking. For Day 21, let's keep things simple with a Growing Star Triangle ⭐.
๐ฏ Today's Challenge
Write a Python program to print exactly this pattern:
Can you create it with the cleanest Python code? ๐
Solution 1 — Using a for Loop
for i in range(1, 11): print("* " * i)
How it works
The loop runs from 1 to 10.
On every iteration, i determines how many stars are printed:
"* " * iSo the number of stars increases row by row.
Solution 2 — Using a while Loop
i = 1 while i <= 10: print("* " * i) i += 1
Here, i starts at 1 and increases after every row until it reaches 10.
Solution 3 — Using a Function
def star_pattern(n): for i in range(1, n + 1): print("* " * i) star_pattern(10)
The function makes the pattern reusable.
For example:
star_pattern(5)will create a smaller triangle.
⚡ Short & Clean Code
for i in range(1, 11): print("* " * i)
๐ฅ One line is enough to generate the complete pattern!
๐ Challenge Yourself
Can you modify this pattern:
- Take the number of rows using input()?
- Print the pattern in reverse?
- Replace * with # or another character?
- Create the same pattern using nested loops?
- Make the triangle hollow?
Drop your solution below! ๐
21 Days. 21 Patterns. Stronger Python Logic. ๐๐ฅ
Learn • Practice • Grow with CLCODING ๐
107 Pattern Plots Using Python
✨ Python Turtle The 3D Ribbon Bloom
Python Developer October 07, 2026 Python Library No comments
Code:
import turtle
import math
import time
screen = turtle.Screen()
screen.setup(700, 700)
screen.bgcolor("#020208")
t = turtle.Turtle()
t.hideturtle()
t.speed(0)
t.width(3)
colors = [
"#ff1744", "#ff2d75",
"#d500f9", "#7c4dff",
"#00e5ff", "#00ff9d"
]
for layer in range(14):
t.color(colors[layer % len(colors)])
for i in range(180):
a = math.radians(i * 2)
# Flower ribbon curve
r = 90 + 85 * math.sin(5 * a + layer * 0.25)
x = r * math.cos(a)
y = r * math.sin(a)
# Slight 3D rotation
rot = math.radians(layer * 4)
X = x * math.cos(rot) - y * math.sin(rot)
Y = x * math.sin(rot) + y * math.cos(rot)
if i == 0:
t.penup()
t.goto(X, Y)
t.pendown()
else:
t.goto(X, Y)
screen.update()
time.sleep(0.002)
time.sleep(0.08)
# ✨ Bold glowing center
for r in range(30, 2, -3):
t.penup()
t.goto(0, -r)
t.dot(r, colors[r % len(colors)])
screen.update()
time.sleep(0.06)
t.penup()
t.goto(0, -5)
t.dot(9, "white")
turtle.done()
Explanation:
1. Import Libraries
import turtleimport mathimport time
- turtle → draws the flower.
- math → handles angles and trigonometry.
- time → adds animation delays.
2. Create the Screen
screen = turtle.Screen()screen.setup(700, 700)screen.bgcolor("#020208")
- Creates a 700×700 window.
- Sets a very dark background.
3. Configure the Turtle
t = turtle.Turtle()t.hideturtle()t.speed(0)t.width(3)
- Creates the drawing turtle.
- Hides the turtle cursor.
- speed(0) gives maximum drawing speed.
- width(3) makes the lines bold.
4. Define Neon Colors
colors = [ "#ff1744", "#ff2d75", "#d500f9", "#7c4dff", "#00e5ff", "#00ff9d"]
- Creates a palette of six neon colors.
- These colors are used for different flower layers.
5. Create Flower Layers
for layer in range(14):
- Creates 14 overlapping flower ribbons.
- Each layer has a slightly different rotation and phase.
6. Select Layer Color
t.color(colors[layer % len(colors)])
- Selects a color from the list.
- % makes the colors repeat after reaching the last color.
7. Generate Curve Points
for i in range(180):
- Creates 180 points for each flower ribbon.
- More points make the curve smoother.
8. Calculate the Angle
a = math.radians(i * 2)
- Converts the angle from degrees to radians.
- The angle increases as the loop progresses.
9. Create the Flower Ribbon Curve
r = 90 + 85 * math.sin(5 * a + layer * 0.25)
- Calculates the changing radius.
- sin() creates the petal-like wave.
- 5 * a produces five major flower lobes.
- layer * 0.25 shifts each layer slightly.
10. Calculate X Coordinate
x = r * math.cos(a)
- Converts the radius and angle into the X position.
11. Calculate Y Coordinate
y = r * math.sin(a)
- Calculates the Y position.
- Together, x and y create the flower curve.
12. Calculate 3D Rotation
rot = math.radians(layer * 4)
- Gives every layer a slightly different rotation.
- Creates a 3D/orbital appearance.
13. Rotate X and Y Coordinates
X = x * math.cos(rot) - y * math.sin(rot)Y = x * math.sin(rot) + y * math.cos(rot)
- Applies a mathematical rotation transformation.
- Produces the twisted ribbon effect.
14. Start Drawing the Layer
if i == 0: t.penup() t.goto(X, Y) t.pendown()
- For the first point, the turtle moves without drawing.
- Then it puts the pen down to start the curve.
15. Connect the Points
else:
t.goto(X, Y)
- Connects every calculated point.
- This forms the complete flower ribbon.
16. Animate the Drawing
screen.update()time.sleep(0.002)
- Updates the screen after each point.
- Adds a tiny delay for the drawing animation.
17. Pause Between Layers
time.sleep(0.08)
- Adds a short pause after completing each ribbon.
- Makes the layer-by-layer effect visible.
18. Create the Glowing Center
for r in range(30, 2, -3):
- Creates multiple circles.
- Radius decreases from 30 to 3.
t.penup()t.goto(0, -r)t.dot(r, colors[r % len(colors)])
- Moves to the center area.
- Draws colorful dots of different sizes.
- Together they create a glowing center.
19. Animate the Center Glow
screen.update()time.sleep(0.06)
- Updates the screen.
- Slows down the center-glow animation.
20. Add White Core
t.penup()t.goto(0, -5)t.dot(9, "white")
- Adds a small white dot.
- Creates a bright core/highlight in the center.
21. Finish the Drawing
turtle.done()
- Keeps the Turtle window open.
Popular Posts
-
What you'll learn Understand the cybersecurity landscape and learn core concepts foundational to security, compliance, and identity so...
-
Introduction Python has become one of the most popular programming languages because of its simple syntax, flexibility, and ability to sol...
-
Guide to NumPy: 2nd Edition – The Complete Reference for Scientific Computing and High-Performance Array Programming in Python Introductio...
-
Introduction Python is one of the most widely used programming languages, powering web development, automation, data analysis, artificial in...
-
Introduction Python is one of the most widely used programming languages in the world. Its readable syntax, flexible features, and extensi...
-
Learn Python: Basic to Advance: Practical & Theory – A Complete Guide to Building Python Skills Understand Python programming from the...
-
Introduction Artificial Intelligence (AI) and Machine Learning (ML) are transforming industries — but working with them effectively requir...
-
Python for Cybersecurity: Build 16 Real Security Tools and Become Job Ready – A Practical Guide to Cybersecurity Automation Explore how Py...
-
Foundations of Robotics: A Multidisciplinary Approach with Python and ROS – A Complete Guide to Modern Robotics Explore robotics through p...
-
Machine learning has rapidly evolved into one of the most influential fields in computer science, driving innovations in artificial intell...


