# How to print a pattern which essentially is an equilateral triangle using WHILE loop?

line = ‘*’
max_length = 5

while len(line) <= max_length:
print(line)
line += “*”

What should I add to it?

``````> line = '*'
> max_length = 5
> space = max_length * " "
>
> while len(line) <= max_length:
>     print(space + line )
>     line += "*"
>     space = space[:-1]
``````

I would just want one more clarification about the
space = space[:-1], How is this function being operated?
What is the change that it brings?

Sure!!

As you may see when you create the variable` space = max_lenght * (" ")`, `being max_lenght = 5`
it will return something like this: `space = " " + " " + " " + " " + " "`
By doing this, `space = space[:-1]`, you are eliminating the last character of the string in order to replace that space by the new character `"*"`
It will work like this:

``````>   " " + " " + " " + " " + " " + "*"
>   " " + " " + " " + " " + "*" + "*"
>   " " + " " + " " + "*" + "*" + "*"
``````

and so on…

3 Likes

Thank you for explaining it in very detail.
Kudos to you…

1 Like

Just one thing more
When I create the function

space = max_length * (" ")
I do not get the result that you have mentioned.
Have you made this for an explanation? Because when I run this code then I get blank output.

Please help me out with it.

Okey!!

The result i´m showing there is just a graphical explanation of what is happening, not the real output. You may not see the real output when you run the code because it´s just a 5 spaces string. It actually is a blank output!!

1 Like