Help in printing a pattern

following is a basic code to print a pyramid of " * " . manner in which for loop is used creates an ambiguity which is pointed out in comments . plz describe how the code progress depending on value given . pattern of output is also given

def pattern(n) :
    k = 2 * n - 2 #spaces
    for i in range(0, n):   #i hope it refers to rows
        for j in range(0, k):   #bit confusing here
            print(end="1") #replace 1 with " " {space} for actual representation
        k = k - 1  #why placed under second foor loop and not the first one ?
        for j in range(0 , i+1): #why use 'j' variable again ? how does it progress
                    print('*',end=" ") #this code prints * in horizontal manner
pattern(3) #function called 

output ;

111* *
11* * *

Maybe you should decide what should happen, and then write code to describe that?

Already having code and not knowing what it does seems backwards. You’re the one putting things in place to make things happen, you’re the one controlling it all.

You could for example write down instructions in English. When does what need to happen? Doesn’t really have anything to do with code. Then you can write code for the individual things, but this only makes sense to do when you’ve already decided what should happen, otherwise how could you write anything at all without knowing what you want?