Python Program to Print Hollow Mirrored Right Triangle Star Pattern

This article shows how to write a Python Program to Print a Hollow Mirrored Right Triangle Star Pattern using a for loop, while loop, and functions. This example uses the nested for loop to iterate and print the Hollow Mirrored Right Triangle Star Pattern.

rows = int(input("Enter Hollow Mirrored Right Triangle Rows = "))

print("====Hollow Mirrored Right Angled Triangle Star Pattern====")

for i in range(1, rows + 1):
    for j in range(0, rows - i):
        print(' ', end = '')
    for k in range(0, i):
        if i == 1 or i == rows or k == 0 or k == i - 1:
            print('*', end = '')
        else:
            print(' ', end = '')
    print()

Output.

Python Program to Print Hollow Mirrored Right Triangle Star Pattern using for loop

This Python program replaces the above for loop with a while loop to print the Hollow Mirrored Right Triangle Star Pattern.

rows = int(input("Enter Hollow Mirrored Right Triangle Rows = "))

print("====Hollow Mirrored Right Angled Triangle Star Pattern====")

i = 1
while i <= rows:
    j = 0
    while j < rows - i:
        print(' ', end = '')
        j = j + 1
    k = 0
    while k < i:
        if i == 1 or i == rows or k == 0 or k == i - 1:
            print('*', end = '')
        else:
            print(' ', end = '')
        k = k + 1
    i = i + 1
    print()

Output

Enter Hollow Mirrored Right Triangle Rows = 14
====Hollow Mirrored Right Angled Triangle Star Pattern====
             *
            **
           * *
          *  *
         *   *
        *    *
       *     *
      *      *
     *       *
    *        *
   *         *
  *          *
 *           *
**************

In this Python example, we created a HollowMirrRightTri function that accepts the rows and character to Print the Hollow Mirrored Right Angled Triangle Star Pattern. It replaces the star in the Hollow Mirrored Right Angled Triangle pattern with a given symbol.

def HollowMirrRightTri(rows, ch):
    for i in range(1, rows + 1):
        for j in range(0, rows - i):
            print(' ', end = '')
        for k in range(0, i):
            if i == 1 or i == rows or k == 0 or k == i - 1:
                print('%c' %ch, end = '')
            else:
                print(' ', end = '')
        print()

rows = int(input("Enter Hollow Mirrored Right Triangle Rows = "))
ch = input("Symbol in Hollow Mirrored Right Triangle = ")

print("====Hollow Mirrored Right Angled Triangle Star Pattern====")
HollowMirrRightTri(rows, ch)

Output

Enter Hollow Mirrored Right Triangle Rows = 15
Symbol in Hollow Mirrored Right Triangle = $
====Hollow Mirrored Right Angled Triangle Star Pattern====
              $
             $$
            $ $
           $  $
          $   $
         $    $
        $     $
       $      $
      $       $
     $        $
    $         $
   $          $
  $           $
 $            $
$$$$$$$$$$$$$$$