π 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 π

0 Comments:
Post a Comment