Code runs fine on offline compiler but shows eof error here

list_numbers=[]
cumulative_sum=0
for i in range(0,5):
ele=int(input())
list_numbers.append(ele)
for i in range(len(list_numbers)):
cumulative_sum+=list_numbers[i]
if cumulative_sum<0:
break
print(list_numbers[i])

Hey shubham,
you are hard coding that it will only run for 5 times. instead perform this

sum =0
numbers = []
while sum >=0:
   n = int(input())
   sum+=n
   if sum<0:
      break
   numbers.append(n)

for n in numbers:
   print(n)

I hope this will work for you
Thanks :slight_smile:

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.