In this program, we will print the pattern A. To write a program to print A pattern we will divide the code into 5 different sections.
section1 : * * *
section2 : * * * * *
section3: * * * *
* * * *
section4: * * * * *
* * * * *
section5: * * * *
* * * *
Steps to solve the program
- Initiate first for loop to print 1st line.
- Using “for i in range(9)”.
- Initiate second for loop to print 2nd line.
- Using “for j in range(9)”.
- Initiate third for loop to print 3rd and 4th line.
- Using “for k in range(2)”.
- Initiate a nested for loop in an above loop using “for l in range (9)”.
- Initiate fourth for loop to print 5th and 6th line.
- Using “for m in range(2)”.
- Initiate a nested for loop in an above loop using “for n in range(9)”.
- Initiate the fifth for loop to print the 7th and 8th lines.
- Using “for k in range(2)”.
- Initiate a nested for loop in an above loop using “for l in range(9)”.
"""
* * *
* * * * *
* * * *
* * * *
* * * * *
* * * * *
* * * *
* * * *
"""
# section1
for i in range(5):
if i == 0 or i == 4:
print(" ", end=" ")
else:
print("*", end=" ")
# section2
print()
for i in range(5):
print("*", end=" ")
# section3
print()
for _ in range(2):
for j in range(5):
if j == 2:
print(" ", end=" ")
else:
print("*", end=" ")
print()
# section4
for _ in range(2):
for i in range(5):
print("*", end=" ")
print()
# section5
for _ in range(2):
for j in range(5):
if j == 2:
print(" ", end=" ")
else:
print("*", end=" ")
print()
Output :
_______________
* * *
* * * * *
* * * *
* * * *
* * * * *
* * * * *
* * * *
* * * *
________________