Python Program to Generate Pyramid Pattern Using Stars

In this python example, we first read number of row from user using built-in function input(). Since function input() returns string value, we need to convert given number to number type using int(). And then we generate pyramid pattern using stars.

Python Program to Generate Pyramid Pattern Using Stars


# Generating 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):
        print('*',end='') # printing * and staying in same line
    print() # printing new line

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

Output

Enter number of rows required: 8
        *
       ***
      *****
     *******
    *********
   ***********
  *************
 ***************