Butterfly Pattern in Python language of Numbers
Butterfly pattern in python language of numbers. In this article, you will learn how to print the Butterfly Pattern in Python language of the numbers using for loop statement.
Example
Enter the height of the pattern: 5
This the butterfly pattern:
1 1
12 21
123 321
1234 4321
123454321
1234 4321
123 321
12 21
1 1
You should have knowledge of the following topics in Python programming to understand this program:
- Python
input()
function - Python
for
loop statement - Python
print()
function
In this program, we used normal functions and statements to print the butterfly pattern in Python language.
Source Code
# Butterfly Pattern in Python language of Numbers
rows, height, digits, space = None, None, None, None
print ("Enter the height of the pattern: ", end="")
height = int (input ())
print ("\nThis the butterfly pattern:\n\n")
for rows in range (1, height):
print (end="\t")
for digits in range (1, rows + 1):
print (digits, end="")
for space in range (1, (2 * (height - rows)) + 1):
print (end=" ")
print (end="\b")
for digits in range (rows, 0, -1):
print (digits, end="")
print (end="\n")
for rows in range (height, 0, -1):
print (end="\t")
for digits in range (1, rows + 1):
print (digits, end="")
for space in range (1, (2 * (height - rows)) + 1):
print (end=" ")
print (end="\b")
for digits in range (rows, 0, -1):
print (digits, end="")
print (end="\n")
Output
Enter the height of the pattern: 5
This the butterfly pattern:
1 1
12 21
123 321
1234 4321
123454321
1234 4321
123 321
12 21
1 1
nested-for
loop statements.
Explanation
In this program, we have taken input 5
size of the pattern then made the calculation using the for
loop statement.