How to make triangle x in python from source code below
<p>Hello I want to ask everybody...
Like this...
I want to make a triangle X or *, like below:</p>

<pre><code>    *
   ***
  *****
 *******
*********
</code></pre>

<p>My Algorithm is like this:</p>

<pre><code>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('*');
</code></pre>

<p>Can anybody tell me how is the source code for python like pascal in above?
Thanks for your answer</p>

<p>Here's a possible solution:</p>

<pre><code>def print_pascals_triangle(levels, debug_char=None):
    triangle = []

    for order in range(levels):
        line = [debug_char] if debug_char is not None else [1]
        for k in range(order):
            if debug_char is None:
                value = line[k] * (order - k) / (k + 1)
                line.append(value)
            else:
                line.append(debug_char)
        triangle.append(line)

    def format_row(row):
        return ' '.join(map(str, row))

    triangle_width = len(format_row(triangle[-1]))
    for row in triangle:
        print(format_row(row).center(triangle_width))
</code></pre>

<p>If you want the real pascal triangle you can use it like this:</p>

<pre><code>for level in range(1, 8):
    print_pascals_triangle(level)
    print('-' * 80)
</code></pre>

<p>And you'll get:</p>

<pre><code>1
--------------------------------------------------------------------------------
 1 
1 1
--------------------------------------------------------------------------------
  1  
 1 1 
1 2 1
--------------------------------------------------------------------------------
   1   
  1 1  
 1 2 1 
1 3 3 1
--------------------------------------------------------------------------------
    1    
   1 1   
  1 2 1  
 1 3 3 1 
1 4 6 4 1
--------------------------------------------------------------------------------
      1      
     1 1     
    1 2 1    
   1 3 3 1   
  1 4 6 4 1  
1 5 10 10 5 1
--------------------------------------------------------------------------------
       1        
      1 1       
     1 2 1      
    1 3 3 1     
   1 4 6 4 1    
 1 5 10 10 5 1  
1 6 15 20 15 6 1
--------------------------------------------------------------------------------
</code></pre>

<p>Otherwise, you can fake the numbers with another character, like this:</p>

<pre><code>for level in range(1, 8):
    print_pascals_triangle(level, debug_char='*')
    print('-' * 80)
</code></pre>

<p>And you'll get this:</p>

<pre><code>*
--------------------------------------------------------------------------------
 * 
* *
--------------------------------------------------------------------------------
  *  
 * * 
* * *
--------------------------------------------------------------------------------
   *   
  * *  
 * * * 
* * * *
--------------------------------------------------------------------------------
    *    
   * *   
  * * *  
 * * * * 
* * * * *
--------------------------------------------------------------------------------
     *     
    * *    
   * * *   
  * * * *  
 * * * * * 
* * * * * *
--------------------------------------------------------------------------------
      *      
     * *     
    * * *    
   * * * *   
  * * * * *  
 * * * * * * 
* * * * * * *
--------------------------------------------------------------------------------
</code></pre>

python algorithm pascal