Where am i wrong! First arrray problem

cook your dish here

def func():
n=int(input())
diff1=0
sum1=0
sum2=0
for i in range(n):
p1,p2=input().split()
p1=int(p1)
p2=int(p2)

    sum1=sum1+p1
    sum2=sum2+p2
    diff=abs(sum1-sum2)
    if(sum2>sum1):
        winn=2
    else:
        winn=1
    if(diff>=diff1):
        diff1=diff
return(f"{winn} {diff1}")

opt=func()
print(opt)

Can you please post the link to the solution, so that we can also get to see the problem statement.

The way functions in python (and almost every other language) work is once it has returned it won’t come back once again unless called again.

So what happens is it gets the answer the first time and then returns and prints the first answer and then ends.

What you could do instead

  1. not use any function and print instead of return.
n=int(input())
diff1=0
sum1=0
sum2=0
for i in range(n):
	p1,p2=input().split()
	p1=int(p1)
	p2=int(p2)
	sum1=sum1+p1
	sum2=sum2+p2
	diff=abs(sum1-sum2)
	if(sum2>sum1):
        	winn=2
	else:
        	winn=1
	if(diff>=diff1):
        	diff1=diff
	print(f"{winn} {diff1}")
  1. use function and print in the loop and call function once
def func():
	n=int(input())
	diff1=0
	sum1=0
	sum2=0
	for i in range(n):
		p1,p2=input().split()
		p1=int(p1)
		p2=int(p2)
		sum1=sum1+p1
		sum2=sum2+p2
		diff=abs(sum1-sum2)
		if(sum2>sum1):
        		winn=2
		else:
        		winn=1
		if(diff>=diff1):
	        	diff1=diff
		print(f"{winn} {diff1}")

func()

There are other ways but I’d recommend 2 .The code seems cleaner and instead of func() , people usually name their function main

yes i got your point thanks for replying