gumelaragum - 1 year ago 84

Pascal Question

Hello I want to ask everybody...

Like this...

I want to make a triangle X or *, like below:

`*`

***

*****

*******

*********

My Algorithm is like this:

`for y:=1 to i do`

for x:=1 to j do

for j-x to 1 do write(' ');

for i to 2*(x-1)+1 do write('*');

Can anybody tell me how is the source code for python like pascal in above?

Thanks for your answer

Answer Source

You can simply do this like that:

```
def triangle(lines):
for i in range(lines):
print(' '*(lines-i) + '*'*(i*2+1))
triangle(5)
```

Output as expected

```
*
***
*****
*******
*********
```