how to create a new variable in a loop
<p>I'm trying to make a function that prints n number of rows of the following sequence  </p>

<pre><code>1  
2 3  
4 5 6  
7 8 9 10  
11 12 13 14 15  
...
</code></pre>

<p>this is what I have so far:</p>

<pre><code>def numTriangle(n):  
    #n = number of rows  
    integers = range(0,n-1)  
    val = 1  
    places = 1  
    for num in integers:  
        print val   
        val = val + 1  
</code></pre>

<p>I've realized that I need to make a loop in which it prints the value, then adds one, but also creates a new variable that is one greater than the previous and prints the original value + 1 and the new variable and so on. How would I create a new variable for each line, or are there any other alternatives to this function, such as printing an additional part of the index for each row?</p>

<p>This produces your output:</p>

<pre><code>n = 6; y= 1;

for i in range(0,n):
    for j in range (0,i):
        print y,
        y = y+1;
    print "\n"
</code></pre>

<p>Note the indentation, indentation defines the scopes.</p>

python jes