What is causing NZEC error in this?

i am doing a question . i have written a simple python code and still its showing NZEC error

n=int(input())       /"error is pointing in this line showing invalid literal for int with base 10 "
k=int(input())
A=[]
for _ in range(n):
    A.append(input())

for x in range(n):
         if(A[x]%k==0):
                print(A[x])

Check the custom input box and provide the input according to your questions then try to run it. In codechef it doesn’t take input automatically if you click on the run button.

1 Like

ok let me do that

what causes NZEC error here ?

On 1 st line he is trying to read a line of input but during runtime it getting EOF as a input because he has not provided any input to the program in the custom input box. If he provide the input in custom input box properly and k≠0 then the program will work fine.

1 Like

no bro it’s not working fine even after giving input
.i got the problem the input order is
6 2
1 2 3 4 5 6

here
6 size of array
2 is an integer k
and next line is folowed by 6 integer values .
how to take input in above mentioned way?

I’m not a Python guy, but looking at random Python submissions, it looks like something along the lines of

n, k = map(int, input().split())

A = list(map(int, input().split()))

for x in range(n):
         if(A[x]%k==0):
                print(A[x])

will do the trick.

Edit:

An alternative also seems popular:

n, k = map(int, input().split())

A = [int(i) for i in input().split()]

for x in range(n):
         if(A[x]%k==0):
                print(A[x])
4 Likes

map did the job , now its working

Your code will work only for the input of bellow formation:
6
2
1
2
3
4
5
6
Because input() function scan whole line.
Now for your given input in first input() function it scan “6 2”.
We can’t convert “6 2” into integer so it will genarate error.
If you want to take input like you have mentioned then use the above snippet of code mentioned by @ssjgz

1 Like

got it bro