Python program to print Pyramid patterns

By Lenin Mishra

Pyramid Pattern #1

Objective:-

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

You can build this pattern by simply using for loops and range.

Code

n = 5

for i in range(1, n+1):
    print(i*'* ')
for i in range(n-1, 0, -1):
    print(i*'* ')

Output

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

Pyramid Pattern #2

Objective:-

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

You can build a pyramid like this by using center() built-in method and for loops.

Code

for i in range(1, 10, 2):
    x = i*'*'
    print(x.center(10))

Output

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

Build your foundation in Python with our self-paced Python Bootcamp for Beginners.