Question: I'm a beginner and trying to learn Python by myself. I've been working on coding some basic shape exercises, so far I have the following code to make a diagonal.

```
size = input('Please enter the size: ')
chr  = raw_input('Please enter the drawing character: ')

row = 1
while row <= size:

    col = 1
    while col < row:
        print ' ', 
        col = col + 1
    print chr

    row = row + 1
print ''

```

I get this output :

```
X
 X
  X
   X

```

I would love some help on how to make this into a triangle like this....

```
X X X X
  X X X
    X X
      X

```

Any explanations on how to make the loop necessary for the characters to show up to make the triangle shaped output would be appreciated.

Answer: 
You can do:

```
>>> for i in xrange(4):
...     print '  ' * i + 'X ' * (4 - i)
...
X X X X
  X X X
    X X
      X

```

The value of `i` goes from 0 to 3 (by using [`xrange`](http://docs.python.org/2/library/functions.html#xrange)) and it prints the string `' '` (two spaces) `i` number of times and it prints `'X '` in total `(4 - i)` number of times. This means it'll print the inverted triangle as desired.
I wrote some code earlier that does shapes, its a bit more detailed than what you might need, but here it is:

```
>>> def make_triangle(size, siblings=1, step=1, char='*'): 
    return '\n'.join([' '.join(line) for line in [[char * (i-(step*sib)) + ' ' * (((size-(step*sib))-(i-(step*sib)))) for sib in xrange(siblings)] for i in xrange(1, size+1)]])

```

Making some triangles:

```
>>> print make_triangle(4, char='X') # standing
X   
XX  
XXX 
XXXX
>>> print make_triangle(4, char='X')[::-1] # hanging (reversed)
XXXX
 XXX
  XX
   X

```

Some of the extra features:

```
>>> print make_triangle(6,3,2)
*                 
**              
***    *       
****   **     
*****  ***  * 
****** **** **

```