Simple input doubt

sum=0
n=[int(x) for x in input().split()]
for i in range(len(n)):
sum=sum+n[i]

if(sum>=0):
    print(n[i])
else:
    break

what is wrong in this code.not able to pass all the test cases

Hey saurbh,
You are not taking inputs in a correct way.
Inputs are supposed to take in next lines. like this
1
8
10
-88
100

But you are taking inputs as 1 8 10 -88 100.
It means you are processing only one element i.e the topmost element.

To correct this, use a while loop till the sum is non negative, and keep asking for new input again and again. And at last print the numbers.

Thanks :slight_smile:

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.