list = [1,2,88,-100,49]
newlist = []
sum = 0
for i in range(0,len(list)):
num = list[i]
sum = sum + num
if(sum>=0):
newlist.append(num)
elif sum<0:
break
print(newlist)
it is giving desired output on IDE bur error in the sample problem. Why?
LINK to IDE https://ide.codingblocks.com/s/156882
Problem in simple input question of python3
Instead of for loop use a while loop since you don’t know how long the list will be or in for loop select a range which you believe would not be crossed.
Also you need to take the list input from the user and not initiate a list yourself with values in it.
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.