why is it not correct?
s=0
l=input()
l=l.split()
l=[int(i) for i in l]
for i in l:
s+=i
if s>=0:
print(i)
else :
break
why is it not correct?
s=0
l=input()
l=l.split()
l=[int(i) for i in l]
for i in l:
s+=i
if s>=0:
print(i)
else :
break
Hey @stutijain578, your logic is absolutely correct. Just try making a small change in your code. Instead of taking a string as input and then splitting and converting into integers, you can try taking the integer input infinitely one by one and then check if sum gets less than zero, you can break. If you still have any doubt, you can revert back anytime
Hope this helps
Happy Coding
it is still giving error
Can you please share your code ?
s=0
while s>=0:
n=int(input())
s+=n
if s>=0:
print(n)
else:
break
i followed indentation but due to pasting it is not showing
I submitted the same code as you did. I am getting all test cases correct.
Maybe you are not selecting the language as python on the upper right hand corner ?
i did;
i selected python 3
Can you send me the screenshot of the code your are submitting ?
Ohh, there is indentation problem in your code.
Wait let me send you the correctly indented code
s=0
while s>=0:
n=int(input())
s+=n
if s>=0:
print(n)
else:
break
I hope this works now
You clicked on Submit code or Compile and Test ?
it was running in jupyter notebook but is giving error on portal
i clicked on compile and test
This error is coming because the program is expecting you to give some input first. Try providing the custom input and then try running it on the portal.
Try to click on Submit code button. It must work.