Programs for printing pyramid technique in python

Programs for printing pyramid technique in python

Pyramid patterns are a popular topic, especially for beginners. Let's see a few different pyramid patterns:

1. Simple Pyramid Pattern

 * *** ***** ******* ********* 
def simple_pyramid(rows): for i in range(rows): print(' '*(rows-i-1) + '*'*(2*i+1)) simple_pyramid(5) 

2. Upside Down Pyramid Pattern

********* ******* ***** *** * 
def upside_down_pyramid(rows): for i in range(rows, 0, -1): print(' '*(rows-i) + '*'*(2*i-1)) upside_down_pyramid(5) 

3. Number Pyramid Pattern

 1 121 12321 1234321 123454321 
def number_pyramid(rows): for i in range(1, rows+1): print(' '*(rows-i), end="") for j in range(1, i+1): print(j, end="") for j in range(i-1, 0, -1): print(j, end="") print() number_pyramid(5) 

4. Character Pyramid Pattern

 A ABA ABCBA ABCDCBA ABCDEDCBA 
def character_pyramid(rows): for i in range(1, rows+1): print(' '*(rows-i), end="") for j in range(65, 65+i): print(chr(j), end="") for j in range(65+i-2, 64, -1): print(chr(j), end="") print() character_pyramid(5) 

To visualize these pyramids, you can call each function one by one. Adjust the number inside the function call to modify the height of the pyramid.


More Tags

sha1 pytorch aar hadoop-yarn spring-jms keycloak-services wpfdatagrid dimensions attr aws-cloudformation

More Programming Guides

Other Guides

More Programming Examples