-1
store_array = list()
test_case = input()
for i in range(int(test_case)) :
    number1 = input()
    number2 = input()
    store_array.append(int(number1))
    store_array.append(int(number2))

j=0
def add(x,y):
    for j in store_array:
        return x + y 
        j=j+1       
print(add(store_array[j],store_array[j+1]))   

what I ve done so far?

testcase - > 2

2 2 3 3

these values are stored in the list under the name store_array

it executes and print the first two values 2 2 and the output 4 will be displayed

how can i step over to next two values and print the consecutives other two input?

Thiyagu
  • 49
  • 2
  • 6

2 Answers2

0

It sounds like you want to step forward every other value. Try this and see if it helps.

Simply change:

j=0
def add(x,y):
    for j in store_array:
        return x + y 
        j=j+1  
print(add(store_array[j], store_array[j+1]))  

To this:

def add(x):
    for j in range(0, len(store_array) -1, 2):
        print(x[j] + x[j+1])      

print(add(store_array))  

This may have the exact behavior you're looking for but it's a good place to start.

K-Log
  • 608
  • 3
  • 18
  • Thanks for v your answer, but doesn't make sense – Thiyagu May 17 '18 at 04:57
  • @Thiyagu Can you explain more? What do you mean it doesn't make sense? – K-Log May 17 '18 at 04:59
  • It remains the same, even updating j = j + 2, and first two values gets printed and the remaining stayed at their place – Thiyagu May 17 '18 at 05:01
  • @Thiyagu My bad, I misinterpreted what you were trying to do. I edited my answer so it should be a good place to start but unfortunately I don't entirely understand what you are trying to do. – K-Log May 17 '18 at 05:19
  • don't change the value of the iterating variable, that's just plain confusing. Instead, use the parameters of `range` to go 2 by 2 – njzk2 May 18 '18 at 04:57
  • @njzk2 updated my answer with your suggestion. I was just trying to keep it in the style of the answer to retain clarity for the question asker. – K-Log May 18 '18 at 05:07
0

Take into consideration the "continue" statement. It makes the loop skipping some iteration.

for i in range(6):
    if i % 2 == 0:
        continue
    print(i)

it will skip all the values that are even.

Superluminal
  • 947
  • 10
  • 23