Program to print the pattern A

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
  1. Initiate first for loop to print 1st line.
  2. Using “for i in range(9)”.
  3. Initiate second for loop to print 2nd line.
  4. Using “for j in range(9)”.
  5. Initiate third for loop to print 3rd and 4th line.
  6. Using “for k in range(2)”.
  7. Initiate a nested for loop in an above loop using “for l in range (9)”.
  8. Initiate fourth for loop to print 5th and 6th line.
  9. Using “for m in range(2)”.
  10. Initiate a nested for loop in an above loop using “for n in range(9)”.
  11. Initiate the fifth for loop to print the 7th and 8th lines.
  12. Using “for k in range(2)”.
  13. 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 :

				
					_______________

    * * *
  * * * * *
  * *   * *
  * *   * *
  * * * * *
  * * * * *
  * *   * *
  * *   * *

________________

				
			

print number patterns

print the pyramid structure

Leave a Comment