sum=0
while True:
if sum<0:
break;
else:
a=input()
sum+=a
print(a)
Count the sum until you encounter a negative number in python. Error shows EOF
Hello Roshan, the issue may be that you are inputting in the same line we need to give the input in diff lines and like this way (a=input()) you are inputting a string you need to specify it as an integer so for that do ( a=int(input()) ) and at last, you also need to put the condition after adding also if it has become negative or not.
So correcting the errors from your code it will be like this:
sum=0
while True:
if sum<0:
break;
else:
a=int(input())
sum+=a
if sum >= 0:
print(a)
I hope it will be clear to you in case there is any difficulty pls let me know I will help you out.
And if it is clear pls mark it as resolve and provide the rating/feedback so that we can improve ourselves.
Thanks
Happy Coding !!
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.