Skip to content

Commit ed4af58

Browse files
Create butterfly_pattern.py
1 parent 03a4251 commit ed4af58

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

other/butterfly_pattern.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def print_butterfly(n): # defining the function
2+
for i in range(1, n + 1): # for upper body of the butterfly
3+
print("*" * i, end="") # for left wing of the butterfly
4+
print(" " * (2 * (n - i)), end="") # for middle spacing
5+
print("*" * i) # for right wing of the butterfly
6+
7+
for i in range(n, 0, -1): # for lower body of the butterfly
8+
print("*" * i, end="") # for left wing of the butterfly
9+
print(" " * (2 * (n - i)), end="") # for middle spacing
10+
print("*" * i) # for right wing of the butterfly
11+
12+
n = int(input("Enter the value of n: ")) # asking the user to enter the value of n and converting the n from string to int data type
13+
print_butterfly(n)

0 commit comments

Comments
 (0)