# Butterfly Pattern in Python
# Website: @codeswithpankaj
def butterfly_pattern(n):
for i in range(n):
for j in range(i + 1):
print("*", end=" ")
spaces = 2 * (n - i - 1)
for j in range(spaces):
print(" ", end=" ")
for j in range(i + 1):
print("*", end=" ")
print()
for i in range(n - 1, 0, -1):
for j in range(i):
print("*", end=" ")
spaces = 2 * (n - i)
for j in range(spaces):
print(" ", end=" ")
for j in range(i):
print("*", end=" ")
print()
# Example usage with n=5
butterfly_pattern(5)
Output
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)