You are on page 1of 18

Print Star Pyramid Patterns in Python

To print star pyramid patterns in python, you have to use two or more than two for
loops. In program that prints pattern contains two for loops, the first loop is
responsible for rows and the second for loop is responsible for columns. Here you
will find the code and learn how to print star pattern, star pyramid pattern, number
pattern, number pyramid pattern, alphabet pattern, alphabet pyramid pattern, etc.

Python Pattern Programs

Here, you will find many code to print different-different patterns in python. All pattern
programs given along with their respective output.

Python Programming Code to Print Patterns

Let's start with pattern programming using python to print star, number and alphabet
pyramid patterns.

Python Pattern Program No.1

Following python program prints the pyramid pattern of stars:

# Python Program - Pattern Program 1

for i in range(0, 5):


for j in range(0, i+1):
print("* ",end="")
print()

Here is the sample run of the above python program to illustrates how to print pattern
using stars:

In first row you will see only 1 star, in second row you will see 2 stars and so on upto
5th row. Printing of star starts from very first column in every row.
Here is the screenshot of python shell where the same program is written and run:

Python Pattern Program No.2

Following python program also prints the pyramid pattern of stars but in different
style:

# Python Program - Pattern Program 2


k = 1
for i in range(0, 5):
for j in range(0, k):
print("* ", end="")
k = k + 2
print()

Here is the sample run of the above python program to illustrates the pattern printing
of stars:

In first row you will see only 1 star, in second row you will see 1+2, that is 3 star and
so on upto 5th row.

Here is the same program on python shell:


Python Pattern Program No.3

Following python program also prints the pyramid pattern of stars but in third style:

# Python Program - Pattern Program 3

k = 8
for i in range(0, 5):
for j in range(0, k):
print(end=" ")
k = k - 2
for j in range(0, i+1):
print("* ", end="")
print()

Here is the sample run of the above python pattern program:

In first row you will see 1 star, in second row you will see 2 star and so on, but the
printing of star starts from right side, or from very first column from right side, or very
last column from left side, or from 1st row and 5th column, or from 0th row and
4th column.
Below is the same program directly written and run on python shell:

Python Pattern Program No.4

Here is another python pattern program prints pyramid pattern of stars in fourth style:
# Python Program - Pattern Program 4

k = 16
tim = 1
for i in range(0, 5):
for j in range(0, k):
print(end=" ")
k = k - 4
for j in range(0, tim):
print("* ", end="")
tim = tim + 2
print()

Here is the sample run of the above Python program:

Printing of star in this program is same as in above one except in first row, you will
se 1 star and in second row you will see 1+2 that is 3 star and so on.

Here is same program on python shell:


Python Pattern Program No.5

Following python program prints the pyramid pattern of numbers:

# Python Program - Pattern Program 5

n = 1
for i in range(0, 5):
for j in range(0, i+1):
print(n, end=" ")
n = n + 1
print()

Here is the sample run of the above python program to show how to print the
pyramid pattern of numbers:

In first row you will see 1, in second row you will see 2 3, in third row you will see 4 5
6 and so on. Numbers in every row stars from very first column.
Here is same program on python shell:

Python Pattern Program No.6

Following python program prints the pyramid pattern of numbers in second style:
# Python Program - Pattern Program 6

for i in range(0, 5):


num = 1
for j in range(0, i+1):
print(num, end=" ")
num = num + 1
print()

Here is the sample run of the above Python program:

In first row you will see 1, in second row you will see 1 2, in third row you will see 1 2
3, and so on.

Pyramid Pattern Program No.7

Following python program print the pattern of stars in another style:

# Python Program - Pattern Program 7

k = 0
rows = 10
for i in range(1, rows+1):
for space in range(1, (rows-i)+1):
print(end=" ")
while k != (2*i-1):
print("* ", end="")
k = k + 1
k = 0
print()
Here is the sample run of the above Python program:

Python Pattern Program No.8

Following python program prints the pyramid pattern of alphabets:

# Python Program - Pattern Program 8

val = 65
for i in range(0, 5):
for j in range(0, i+1):
ch = chr(val)
print(ch, end=" ")
val = val + 1
print()

Here is the sample run of the above Python program to illustrates how to print
pyramid pattern of alphabets:
Python Pattern Program No.9

Following python program also prints the pyramid pattern of alphabets in different
style:

# Python Program - Pattern Program 9

val = 65
for i in range(0, 5):
for j in range(0, i+1):
ch = chr(val)
print(ch, end=" ")
val = val + 1
print()

Here is the sample run of the above Python program:

You will see A in first row, B B in second row, C C C in third row and so on.
Python Pattern Program No.10

Below is another python program print pattern of stars:

# Python Program - Pattern Program 10

for i in range(0, 5):


for j in range(5, i, -1):
print("* ", end="")
print()

Here is the sample run of the above Python program:


Python Pattern Program No.11

Here is another python program to print pattern of numbers:

# Python Program - Pattern Program 11

num = 1
for i in range(0, 5):
for j in range(5, i, -1):
print(num, end=" ")
num = num + 1
print()
num = 1

Here is the sample run of the above Python program:


Python Pattern Program No.12

This is another version of pattern program in python to print pattern of numbers:

# Python Program - Pattern Program 12

num = 1
incr = 1
for i in range(0, 5):
for j in range(0, incr):
print(num, end=" ")
num = num + 1
print()
incr = incr + 2

Here is the sample run of the above Python program:


Python Pattern Program No.13

This is the another version of pattern program in python to print pattern of numbers:

# Python Program - Pattern Program 13

num = 1
count = 0
decr = 8
for i in range(0, 5):
for k in range(0, decr):
print(end=" ")
for j in range(0, i):
count = count + 1
num = count
temp = num
for j in range(0, i):
print(num, end=" ")
num = num - 1
print()
num = temp
decr = decr - 2

Here is the sample run of the above Python program:


Python Pattern Program No.14

Below is another version of pattern printing program in python to illustrates how to


print pattern of alphabets:

# Python Program - Pattern Program 14

incr = 1
val = 65
for i in range(0, 5):
for j in range(0, incr):
ch = chr(val)
print(ch, end=" ")
val = val + 1
incr = incr + 2
print()

Here is the sample run of the above Python program:


Python Pattern Program No.15

Let's see another pattern program in python to print pattern of alphabets:

# Python Program - Pattern Program 15

decr = 8
count = 64
val = 65
for i in range(0, 5):
for k in range(0, decr):
print(end=" ")
for j in range(0, i+1):
count = count + 1
val = count
temp = val
for j in range(0, i+1):
ch = chr(val)
print(ch, end=" ")
val = val - 1
val = temp
decr = decr - 2
print()

Here is the sample run of the above Python program:

You might also like