Remove extra space from pattern

Viewed 285

This is a pattern for 180 degree triangle pattern in python

for i in range(0,n):
        for j in range(n,-1,-1):
            if(j<=i):
                    print("#",end="")
            else:
                    print(" ",end="")
        print("")

with this output is coming like this:

      #
     ##
    ###
   ####
  #####
 ######

As you can see it has extra spaces What I want is:

     #
    ##
   ###
  ####
 #####
######
1 Answers

Try this :

n = int(input())
for i in range(1,n+1):
        for j in range(n,0,-1):
            if(j<=i):
                    print("#",end="")
            else:
                    print(" ",end="")
        print("")
Related