How to do sum in Loop
<p>I have a exercise ,Input data will contain the total count of pairs to process in the first line.
The following lines will contain pairs themselves - one pair at each line.
Answer should contain the results separated by spaces.
My code:</p>

<pre><code>    n = int(raw_input())
    sum = 0

    for i in range(n):
        y = raw_input().split(" ")
        for i in y:
            sum = sum + int(i)


    print sum          
</code></pre>

<p>With my code , I come the Sum together, but I will that the results to come separated by spaces . Thanks for yours help .</p>

<p>Uh oh, it looks like you're reusing the same variable <code>i</code> in the inner loop as the outer loop -- this is bad practice and can lead to bugs down the road. </p>

<p>What you're doing currently is adding both elements in each pair to sum and then printing that at the end, you can fix this in two different ways.</p>

<ol>
<li><p>You can sum each pair, convert the sum to a string, and then concatenate that with your the rest of the sums as strings, or</p></li>
<li><p>You can print the sum of each pair immediately after summing them with <code>print sum,</code> which will print the number without the newline so that you can print all the results on a single line.</p></li>
</ol>

python loops sum