Simple input problem

a = [int(x) for x in input(“Enter the no.s”).split(’,’)]
sum = 0

for i in range(len(a)):
sum = sum + a[i]
if sum > 0:
print(a[i])
else:
break

sir, where can i give the constraint (-1000 to 1000) in my code???

Hey @Roopa1i_ma1hotra, you don’t need to specify the constraints anywhere in your code. Python will take care of that on it’s own !

I hope this helps !
Happy Learning ! :slightly_smiling_face:

then what is wrong with this code?

Hey @Roopa1i_ma1hotra, the error in this code is that you are taking the input in the wrong format which does not match with that specified in the question. You have to take input from the user one by one in a new line, something like this :

sum=0
while(True):
   a = int(input())
   sum = sum + a
   
   Rest of the logic of code 

I hope you are able to understand !
Happy coding :slightly_smiling_face:

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.