Star Pattern in Python: Esha Gupta
Star Pattern in Python: Esha Gupta
Esha Gupta
Associat e Senior Execut ive
Updated on Sep 12, 2024 16:22 IST
Pattern programs in Python are a type of problem that uses loops to
produce different patterns of numbers, stars (*), or other characters. In this
blog, we will explore the star pattern in Python further.
Star pattern in Python are popular for practising nested loop control structures.
They involve using loops to print out a particular pattern of stars (*) on the screen.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 13-Sep-20 24.
Steps to Solve
The butterfly pattern consists of two symmetrical halves with increasing and
decreasing star counts.
Copy code
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 13-Sep-20 24.
Copy code
Complete Code
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 13-Sep-20 24.
Copy code
n=5
This basic approach can be adapted to solve various other star patterns in Python.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 13-Sep-20 24.
Pyramid Star Pattern
Diamond Star Pattern
Code
Copy code
for i in range(5):
for j in range(5):
print("*", end="")
print()
2. Inverted Pyramid Star Pattern: This pattern forms an inverted pyramid with
stars.
Code
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 13-Sep-20 24.
Copy code
for i in range(5):
for j in range(i):
print(" ", end="")
for j in range(i, 5):
print("* ", end="")
print()
Code
Copy code
for i in range(5):
for j in range(5, i, -1):
print(" ", end="")
for k in range(i + 1):
print("* ", end="")
print()
4. Diamond Star Pattern: This pattern prints a diamond shape with stars.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 13-Sep-20 24.
Code
Copy code
n=5
5. Hollow Square Star Pattern: This pattern prints a square but leaves the
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 13-Sep-20 24.
middle portion hollow.
Code
Copy code
n=5
for i in range(n):
for j in range(n):
if i == 0 or i == n - 1 or j == 0 or j == n - 1:
print("*", end="")
else:
print(" ", end="")
print()
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 13-Sep-20 24.
Number Pat t ern Programs in Java
Pattern pro grams in Java are a type o f pro blem that use nested lo o ps to
pro duce different patterns o f numbers, stars (*), o r o ther characters. In this blo g
we will dive...re ad m o re
Conclusion
Thus, the star pattern in Python is essential to foundational programming
learning and practice. They help understand the use and manipulation of loops and
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 13-Sep-20 24.
control statements and enhance logical thinking and problem-solving skills.
FAQs
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 13-Sep-20 24.