Print the alphabet pattern ‘O’

In this python program, we will print the alphabet pattern ‘O’, with a special character *. pattern printing programs are very helpful to get expertise on loop fundamentals and flow design.

Please refer to the image, we consider a square of 7×7 size, which means 7 rows and 7 colons, Now in this square, the circle marked as green will be part of the ‘0’ pattern.

Steps to solve the program
o pattern2

1).  In this program have considered the matrix of 7*7 and where each row colon’s initial index position is zero as shown in the image.
2). In the code first loop act and the row and nested loop act as colons to print the pattern.
3). First loop value range is 0-6 and the nested loop range is the same 0-6.
4). First If condition makes sure only three * will print in the first and last row.
5). Second if the condition makes sure only two * should print at 1 and 5 indexes of the colon, for remaining 5 rows. 

 

				
					for row in range(0, 7):
        for column in range(0, 7):
            # here in first and last row we want to three *
            if (row == 0 or row == 6) and (1 < column < 5) :
                print("*", end=' ')
            # here from 2 to 6 row, * will print on 1 and 5 index only.
            elif (0 < row <= 5) and (column ==1 or column ==5):
                print("*", end=' ')
            else:
                print(" ", end=' ')
        print()
  
				
			

Output :

				
					---------

   ***
  *   *
  *   *
  *   *
  *   *
  *   *
   ***
   
---------   
				
			

accepts a string and calculates the number of digits and letters

print all natural numbers from 1 to n

Leave a Comment