Here is a quick approach to print pyramid patterns with Python Programming Language. It’s a simple and easy approach that anyone can easily understand and try on their own. I am taking rows value in every for loop, but I have just mentioned once on the very first code block. However, I had to update the code blocks with all the input method.
#1
def pyra1(rows):
for row in range(rows):
print("* "*row)
pyra1(10)
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
#2
def pyra2(rows):
for row in range(rows):
print("* "*(rows-row))
pyra2(10)
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
#3
def pyra5(rows):
for row in range(rows):
print(" "*(rows-row), "* "*row)
pyra5(10)
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
#4
def pyra1(rows):
for row in range(rows):
print("* "*row)
pyra1(10)
def pyra2(rows):
for row in range(rows):
print("* "*(rows-row))
pyra2(10)
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
#5
def pyra(rows):
for row in range(rows):
print(" "*(rows-row), "* "*row)
pyra(10)
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
#6
def pyra1(rows):
for row in range(rows):
print(" "*(rows-row), f"{row} "*row)
pyra1(10)
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
#7
def pyra2(rows):
for row in range(rows):
print(" "*row, "* "*(rows-row))
pyra2(10)
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
#8
def pyra3(rows):
for row in range(rows):
print(" "*row, f"{row} "*(rows-row))
pyra3(10)
0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3
4 4 4 4 4 4
5 5 5 5 5
6 6 6 6
7 7 7
8 8
9
#9
def pyra(rows):
for row in range(rows):
print(" "*(rows-row),f"{row} "*row)
pyra(10)
def pyra1(rows):
for row in range(rows):
print(" "*row, f"{row} "*(rows-row))
pyra1(10)
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3
4 4 4 4 4 4
5 5 5 5 5
6 6 6 6
7 7 7
8 8
9
#10
def pyra2(rows):
for row in range(rows):
print(" "*(rows-row),"* "*row)
pyra2(10)
def pyra3(rows):
for row in range(rows):
print(" "*row, "* "*(rows-row))
pyra3(10)
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Contents
show