Python Program to Print Right Triangle, Half Pyramid Pattern

Right Triangle, Pyramid Pattern

Python programs to print the half pyramid pattern have been given here. Both the right half and left half of the pyramid using *, numbers and letters have been covered.






1. Program & output to print the right half pyramid pattern




1.1. Python Program & output to print the right half pyramid pattern using *

Code has been copied
#**********************************
#       alphabetacoder.com
#Python program to print the right
#half pyramid pattern using *
#**********************************


# take input
row = int(input("Enter the number of rows: "))

# new line
print("")

# display the pattern
for i in range(1, row + 1):
    # print *
    for j in range(1, i + 1):
        print("*", end = "")
        
    # new line
    print("")

Output


Enter the number of rows: 6


*

**

***

****

*****

******




1.2. Python Program & output to print the right half pyramid pattern using numbers

Code has been copied
#**********************************
#  	alphabetacoder.com
#Python program to print the right
#half pyramid pattern using numbers
#**********************************

# take input
row = int(input("Enter the number of rows: "))

# new line
print("")

# display the pattern
for i in range(1, row + 1):
    # print numbers
    for j in range(1, i + 1):
        print(j, end = " ")
        
    # new line
    print("")

Output


Enter the number of rows: 6


1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

1 2 3 4 5 6




1.3. Python Program & output to print the right half pyramid pattern using alphabets

Code has been copied
#************************************
#       alphabetacoder.com
#Python program to print the right
#half pyramid pattern using alphabets
#************************************

# take input
row = int(input("Enter the number of rows: "))

# new line
print("")

# display the pattern
for i in range(1, row + 1):
    # print letters
    for j in range(1, i + 1):
        print(chr(j + 64), end = " ")
        
    # new line
    print("")

Output


Enter the number of rows: 6


A

A B

A B C

A B C D

A B C D E

A B C D E F




2. Program & output to print the left half pyramid pattern




2.1. Python Program & output to print the left half pyramid pattern using *

Code has been copied
#*************************************
#       alphabetacoder.com
#Python program to print the left half
#of the pyramid pattern using *
#*************************************

# take input
row = int(input("Enter the number of rows: "))

# new line
print("")

# display the pattern
for i in range(1, row + 1):
    # print space
    for j in range(1, row - i + 1):
        print(" ", end = "")
    # print *
    for j in range(1, i + 1):
        print("*", end = "")
        
    # new line
    print("")

Output


Enter the number of rows: 6


     *

    **

   ***

  ****

 *****

******




2.2. Python Program & output to print the left half pyramid pattern using numbers

Code has been copied
#**************************************
#    	alphabetacoder.com
#Python program to print the left half
#of the pyramid pattern using numbers
#**************************************

# take input
row = int(input("Enter the number of rows: "))

# new line
print("")

# display the pattern
for i in range(1, row + 1):
    # print space
    for j in range(1, 2 * (row - i) + 1):
        print(" ", end = "")
    # print numbers
    for j in range(1, i + 1):
        print(j, end = " ")
        
    # new line
    print("")

Output


Enter the number of rows: 5


        1

      1 2

    1 2 3

  1 2 3 4

1 2 3 4 5




2.3. Python Program & output to print the left half pyramid pattern using alphabets

Code has been copied
#**************************************
#    	alphabetacoder.com
#Python program to print the left half
#of the pyramid pattern using alphabets
#**************************************

# take input
row = int(input("Enter the number of rows: "))

# new line
print("")

# display the pattern
for i in range(1, row + 1):
    # print space
    for j in range(1, 2 * (row - i) + 1):
        print(" ", end = "")
    # print letters
    for j in range(1, i + 1):
        print(chr(j + 64), end = " ")
        
    # new line
    print("")

Output


Enter the number of rows: 5


        A

      A B

    A B C

  A B C D

A B C D E




3. Program & output to print the right half pyramid pattern




3.1. Python Program & output to print the inverted half pyramid pattern using *

Code has been copied
#*************************************
#       alphabetacoder.com
#Python program to print the inverted
#half pyramid pattern using *
#*************************************

# take input
row = int(input("Enter the number of rows: "))

# new line
print("")

# display the pattern
for i in range(1, row + 1):
    # print *
    for j in range(row, i - 1, -1):
        print("*", end = "")
        
    # new line
    print("")

Output


Enter the number of rows: 6


******

*****

****

***

**

*




3.2. Python Program & output to print the inverted half pyramid pattern using numbers

Code has been copied
#*************************************
#       alphabetacoder.com
#Python program to print the inverted
#half pyramid pattern using numbers
#*************************************

# take input
row = int(input("Enter the number of rows: "))

# new line
print("")

# display the pattern
for i in range(1, row + 1):
    # print numbers
    for j in range(row, i - 1, -1):
        print((row - j + 1), end = " ")
        
    # new line
    print("")

Output


Enter the number of rows: 6


1 2 3 4 5 6

1 2 3 4 5

1 2 3 4

1 2 3

1 2

1




3.3. Python Program & output to print the inverted half pyramid pattern using alphabets

Code has been copied
#*************************************
#       alphabetacoder.com
#Python program to print the inverted
#half pyramid pattern using alphabets
#*************************************

# take input
row = int(input("Enter the number of rows: "))

# new line
print("")

# display the pattern
for i in range(1, row + 1):
    # print letters
    for j in range(row, i - 1, -1):
        print(chr(row - j + 65), end = " ")
        
    # new line
    print("")

Output


Enter the number of rows: 6


A B C D E F

A B C D E

A B C D

A B C

A B

A