Python Program to Print Mirrored Right Triangle Star Pattern

Write a Python Program to Print Mirrored Right Triangle Star Pattern using For Loop and While Loop with an example.

Python Program to Print Mirrored Right Triangle Star Pattern using For Loop

This Python program allows user to enter the total number of rows. Next, we used Nested For Loop, and If Else to print mirrored right angled triangle of stars pattern from 1 to user-specified maximum value (rows).

# Python Program to Print Mirrored Right Triangle Star Pattern

rows = int(input("Please Enter the Total Number of Rows  : "))

print("Mirrored Right Triangle Star Pattern") 
for i in range(1, rows + 1):
    for j in range(1, rows + 1):
        if(j <= rows - i):
            print(' ', end = '  ')
        else:
            print('*', end = '  ')
    print()
Python Program to Print Mirrored Right Triangle Star Pattern 1

Python Program to Print Mirrored Right Triangle Stars Example 2

This Python allows the user to enter his/her own character. Next, it prints the mirror right triangle of user-specified character.

# Python Program to Print Mirrored Right Triangle Star Pattern

rows = int(input("Please Enter the Total Number of Rows  : "))
ch = input("Please Enter any Character  : ")

print("Mirrored Right Triangle Star Pattern") 
for i in range(1, rows + 1):
    for j in range(1, rows + 1):
        if(j <= rows - i):
            print(' ', end = '  ')
        else:
            print('%c' %ch, end = '  ')
    print()
Please Enter the Total Number of Rows  : 12
Please Enter any Character  : $
Mirrored Right Triangle Star Pattern
                                 $  
                              $  $  
                           $  $  $  
                        $  $  $  $  
                     $  $  $  $  $  
                  $  $  $  $  $  $  
               $  $  $  $  $  $  $  
            $  $  $  $  $  $  $  $  
         $  $  $  $  $  $  $  $  $  
      $  $  $  $  $  $  $  $  $  $  
   $  $  $  $  $  $  $  $  $  $  $  
$  $  $  $  $  $  $  $  $  $  $  $  
>>> 

Python Program to Print Mirrored Right Triangle of Stars using While Loop

This mirrored right angled triangle of stars program is the same as the first example. However, we replaced the For Loop with While Loop

# Python Program to Print Mirrored Right Triangle Star Pattern

rows = int(input("Please Enter the Total Number of Rows  : "))

print("Mirrored Right Triangle Star Pattern")
i = 1
while(i <= rows):
    j = 1
    while(j <= rows):
        if(j <= rows - i):
            print(' ', end = '  ')
        else:
            print('*', end = '  ')
        j = j + 1
    i = i + 1
    print()
Please Enter the Total Number of Rows  : 15
Mirrored Right Triangle Star Pattern
                                          *  
                                       *  *  
                                    *  *  *  
                                 *  *  *  *  
                              *  *  *  *  *  
                           *  *  *  *  *  *  
                        *  *  *  *  *  *  *  
                     *  *  *  *  *  *  *  *  
                  *  *  *  *  *  *  *  *  *  
               *  *  *  *  *  *  *  *  *  *  
            *  *  *  *  *  *  *  *  *  *  *  
         *  *  *  *  *  *  *  *  *  *  *  *  
      *  *  *  *  *  *  *  *  *  *  *  *  *  
   *  *  *  *  *  *  *  *  *  *  *  *  *  *  
*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  
>>>