Generate two loops with different ranges
<p>I am trying to generate two loops and I want the second loop to count from the first number of my first loop in range of 10 until 80. It looks like this:</p>

<pre><code>0
0
1
12345678910
2
234567891011121314151617181920
3
3456789101112131415161718192021222324252627282930
</code></pre>

<p>Continue like this until 8 in my first loop and 80 in my second.
My code so far</p>

<pre><code>count = 1
for i in range(9):
    for j in range(0, i,10):
        print(count, end=80)
        count = count i+1

         print()
</code></pre>

<p>Any suggestion on what I am doing wrong will be very helpful.</p>

<p>You have a number of syntax errors in your code.  I think I have a working version for you here:</p>

<pre><code>for i in range(9):
    end_second_loop = (i * 10) + 1
    print(i)
    for j in range(i, end_second_loop):
        print(j, end='')
    print()
</code></pre>

<p>I'll also go over what was wrong syntactically with your first code.  </p>

<p>In order to get your code to run, an extra space before your last <code>print()</code> call had to be removed, the <code>end=80</code> had to be changed (<code>end</code> in that case must be a string, such as <code>end=''</code> to force <code>print()</code> not to add a newline), and a <code>+</code> was missing from <code>count = count i+1</code>.  I imagine you wanted:</p>

<pre><code>count = count + i + 1
</code></pre>

<p>That gets it running, but not yet producing the right output.  Based on the way you formatted your desired output, 3 <code>print()</code> statements are necessary.</p>

<ol>
<li>The first one prints the number from the outer loop</li>
<li>The next one prints the count from the first number up to that number multiplied by 10 (using <code>end=''</code> so it all prints on on line)</li>
<li>The last one is an empty statement, in order to add a newline character</li>
</ol>

<p>Inside the outer loop, but before entering the inner loop, I defined <code>end_second_loop</code> to let the second loop know when to stop, and it updates on each iteration of the outer loop.  Then the inner loop gets to do its work.  Importantly, the 3rd <code>print()</code> statement must be called <strong>outside</strong> the inner loop, but <strong>inside</strong> the outer loop.  As you had it at first, it was being called inside the inner loop, preventing it from printing all on one line.  By moving it out of that loop, and to the end of the first loop, it only prints a newline once on each iteration of the outer loop, and only after the inner loop is done printing all of its numbers to one line.</p>

<p>I hope that helps.</p>

python loops nested