How do I do this in Python?

Problem: Given a list of numbers, stop processing input after the cumulative sum of all the input becomes negative.
So, I need to add one integer at a time, and then check if the total is negative. If it isn’t, then I add the next, and so on. When it becomes negative, I need to print all the integers before it. How do I do this in Python 3?

Hello @Sahrid, you can use the while loop for this with always true condition and breaks it whenever the sum becomes negative.
Like,

while True:
    # condition for you logic
    # if the sum becomes negative then break it 
    if sum < 0:
         break

I hope the way we need to write the code is clear to you.

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.