| Small Star Python Program for Beginners | 
In this article, we are going to print out the hollow triangle or pyramid in python.
If you are looking for a Python tutorial series then it's here
def pyramid(num):
    
    for i in range(1,num+1):
        for j in range(num-i):
            print(" ", end="")
        for j in range(1, (2*i-1)+1):
            if i == num or j == 1 or j == (2*i-1):
                print('*', end='')
            else:
                print(" ", end="")
        print()
        
pyramid(10)
The output of the program is:
         *
        * *
       *   *
      *     *
     *       *
    *         *
   *           *
  *             *
 *               *
*******************
Comments
Post a Comment