Skip to main content

Print out Inverted Triangle using Python

 

Python Competitive Programming questions


In this article, we are going to write code in python to print out an inverted triangle.


If you are looking for a Python Tutorial then it's here.



def InvertedTriangle(rows):
    spaces = 0
    stars = 2*rows-1
    for i in range(1, rows+1):
        print(' ' * spaces + '*' * stars)
        stars -=2
        spaces +=1
        
def main():
    TotalRows = int(input('Enter the number of rows: '))
    InvertedTriangle(TotalRows)
    
main()


The output of the code is:


Enter the number of rows: 10
*******************
 *****************
  ***************
   *************
    ***********
     *********
      *******
       *****
        ***
         *
    

Comments