Python Error in codeChef need insight

Hi so i was writing a code in the beginner section while my code was working perfectly in custom windows and inputs i was getting NZec and EOF. code was perfect but when i ran the code like this

for i in range(int(N)):
Studentdata=input().split( )
Studentdata=[int(i) for i in Studentdata]
if Studentdata[-1]>10:
elif Studentdata[-1]<=10 and (sum(Studentdata[0:K]))>=M:

it produced error but if i put the code in try except it worked . I want to know if there is any particular reason it happens in python.

if you want to assign value to N,M,K then you have to use list comprehension. Here do like this.
N,M,K =[int(x) for x in input().split()]

1 Like

I did it like that but the error still persisted. I think the error appears in the case of input() not matching the constraints but if I put code in try/except it works. the error appears in line1 so I think it has something to do with input.
your help is very much appreciated please tell any more insights if you can thanks :slight_smile:

You can also try this method of getting multiple inputs in the same line.

For multiple values :

  • N, M, K = map(int, input().split())

For list or tuples:

  • arr = list(map(int, input().split())

This is will simply map the input to the corresponding values. Hope this would be helpful. Happy coding. :smiley:

1 Like