Python PatternProgram for Beginners |
In this article, we are going to print out the hollow inverted triangle or pyramid in python.
If you are looking for a Python tutorial series then it's here
def pyramid(n):
for i in range(1, n+1):
for j in range(1, i):
print(" ", end="")
for j in range(1, (n*2 - (2*i - 1))+1):
if i == 1 or j == 1 or j ==(n*2 -(2*i-1)):
print("*", end="")
else:
print(" ", end="")
print()
pyramid(10)
The output of the program is:
*******************
* *
* *
* *
* *
* *
* *
* *
* *
*
Comments
Post a Comment