Python Program to Print Inverted Triangle Star Pattern

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

rows = int(input("Enter Inverted Triangle Pattern Rows = "))

print("====Inverted Triangle Star Pattern====")

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

Output.

Python Program to Print Inverted Triangle Star Pattern using for loop

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

rows = int(input("Enter Inverted Triangle Pattern Rows = "))

print("====Inverted Triangle Star Pattern====")

i = rows
while i > 0:
    j = 1
    while j <= rows - i:
        print(' ', end = '')
        j = j + 1
    k = 1
    while k < i * 2:
        print('*', end = '')      
        k = k  + 1
    i = i - 1
    print()

Output

Enter Inverted Triangle Pattern Rows = 15
====Inverted Triangle Star Pattern====
*****************************
 ***************************
  *************************
   ***********************
    *********************
     *******************
      *****************
       ***************
        *************
         ***********
          *********
           *******
            *****
             ***
              *

In this Python example, we created an InvertedTriangle function that accepts the rows and characters to Print the Inverted Triangle Star Pattern. It replaces the star in the Inverted Triangle pattern with a given symbol.

def InvertedTriangle(rows, ch):
    for i in range(rows, 0, -1):
        for j in range(1, rows - i + 1):
            print(' ', end = '')
        for k in range(1, i * 2):
            print('%c' %ch, end = '')   
        print()


rows = int(input("Enter Inverted Triangle Pattern Rows = "))
ch = input("Symbol in Inverted Triangle = ")

InvertedTriangle(rows, ch)

Output

Enter Inverted Triangle Pattern Rows = 11
Symbol in Inverted Triangle = $
$$$$$$$$$$$$$$$$$$$$$
 $$$$$$$$$$$$$$$$$$$
  $$$$$$$$$$$$$$$$$
   $$$$$$$$$$$$$$$
    $$$$$$$$$$$$$
     $$$$$$$$$$$
      $$$$$$$$$
       $$$$$$$
        $$$$$
         $$$
          $