How to print Pyramid in Python
![how to print pyramid in python](https://pythonpoint.net/wp-content/uploads/2021/01/how-to-print-pyramid-in-python-1024x576.jpg)
In this article, we will learn to print pyramid pattern in Python.
These pyramid patterns can be created with the help of for loops.
def pyramid(n): # no of rows for i in range(n): #no of columns for j in range(i+1): print('* ', end = '') print('\r') pyramid(4)
Output:
* * * * * * * * * *
Triangle Pyramid Pattern:
def try_pyramid(n): k = n-1 for i in range(n): for j in range(k): print(end = ' ') k -= 1 for l in range(i+1): print('* ', end = '') print('\r') try_pyramid(5)
Output:
* * * * * * * * * * * * * * *
Subscribe
Login
Please login to comment
0 Discussion