Python Program to Print Hollow Star Pyramid Pattern

This python program generates hollow pyramid pattern made up of stars up to n lines.

In this python example, we first read number of row in the hollow pyramid pattern from user using built-in function input(). And then we use using python's for loop to print hollow pyramid pattern.

Python Source Code: Pyramid Pattern

# Generating Hollow Pyramid Pattern Using Stars

row = int(input('Enter number of rows required: '))

for i in range(row):
    for j in range(row-i):
        print(' ', end='') # printing space required and staying in same line
    for j in range(2*i+1):
        if j==0 or j==2*i or i==row-1:
            print(' ', end='')
    print() # printing new line

In this program print() only is used to bring control to new lines.

Output: Pyramid Pattern

Enter number of rows required: 12
           * *
          *   *
         *     *
        *       *
       *         *
      *           *
     *             *
    *               *
   *                 *
  *                   *