Print stars like a Triangle in Python

This Code will lets you to print stars in Triangle Form

Source code :



SYMBOL = "*" #Change the Symbol
    
def triangle(i, t=0):
    if i == 0:
        return 0
    else:
        print(' ' * ( i + 1 ) + SYMBOL * ( t * 2 + 1 ))
        return triangle( i - 1, t + 1 )
        
triangle(5) # Calling the triagle function to print 5 lines of stars


Output :

      *
     *
    ***
   *
  ***

Notes :

You can change the symbol star , just by changing the SYMBOL variable.

Here is a simple code for your understanding

for l in range (0,6):
    for i in range (0,l):
        print("*",end="")

    print()

The output looks as follows

*
**
***
****
*****

Output :


                

Comments :