 # Weird NZEC in "uncle Johny"

I’m trying to solve the question “Uncle Johny”. Seems pretty easy, but for some reason I’m getting a runtimeError NZEC.
This is the code. Can anyone help me with? I really don’t undestand how it doesn’t have a zero exit

``````t = int(input())
for _ in range(t):
n = int(input())
A = list(map(int, input().split(' ')))
u = int(input())

value = A[u - 1]
A.sort()
p = A.index(value) + 1

print(p)
``````

okay. In your code you declared A as:
`A = list(map(int, input().split('')))`

if you get NZEC again then you should write `int(A.index(value)` instead of `A.index(value)`
You can see my solution which worked perfectly:

``````# cook your dish here
s = []
t=int(input())

try :
while t>0:
t=t-1
k=int(input())
s = list(map(int,input().split()))
p = int(input())
val=s[p-1]
s.sort()
p = 1+ int(s.index(val))
print(p)
except:
pass
``````
1 Like

I apreciate your help, however, I believe I don’t have an extra bracket.

``````A = list(map(int, input().split(' ')))
s = list(map(int, input().split()))
``````

The first line is my code, the second is yours. Both have 3 brackets in the end, not 2. Also, when I tried to make it 2 brackets, my code didn’t run on my IDE

your code is correct, the test cases have whitespaces, it was probably from before codechef accepted python solutions.

3 Likes

Thanks for the help! That makes me feel better, as I was lost with the error

Is there a way to correct it?

Also, what did you mean with white cases in the test cases. Are there whitespaces between the test cases, like:

firstTestCase

secondTestCase

I’ll be grateful if you manage to explain this to me, so I can undestand more about this kind of question.

I’m sorry, but I’m not proficient enough in python to help you with that, I normally use c++.
But as for whitespaces, try the 2 test cases, the first one is the example input, and the second one is also the example input, but without whitespaces.

``````3
4
1 3 4 2
2
5
1 2 3 9 4
5
5
1 2 3 9 4
1
``````
``````3
4
1 3 4 2
2
5
1 2 3 9 4
5
5
1 2 3 9 4
1
``````

You will get a nzec error on the input because the third array ends with a whitespace. Use the arrow key from left to right on the third array for both and you’ll see what i mean.

Oh, I see. Thanks. I think I know a way to fix it : )

Ok i figured it out, look at the code if you need help, but you won’t have to do this in the newer sums

``````t = int(input())
for _ in range(t):
n = int(input())
seq=[]
num=""
A = input()
for i in A:
if(i!=' '):
num+=i
else:
seq.append(int(num))
num=""
if(num!=""):
seq.append(int(num))
u = int(input())
value = seq[u - 1]
seq.sort()
p = seq.index(value) + 1
print(p)
``````
``````A = list(map(int, input().split()))
``````

seems to be whitespace-tolerant enough 3 Likes

Oops, it seems i don’t know python at all. But I thought

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

is equivalent to

``````A = list(map(int, input().split(' ')))
``````
1 Like

Me neither But based on local testing, they seem to behave differently, for me, with the former ignoring superfluous whitespace. Dunno why 3 Likes

Oh i get it.

``````A = list(map(int, input().split(' ',n-1)))
``````

This works, because by default it only checks numbers, whereas in the other one, it checks after every whitespace, but you can bound it, by using the second parameter.

1 Like

That is very clever.

Also, .split() instead of split(’ ') works, too, since the default paramer splits using any white spaces(space, newline, etc). I didn’t found it, the other guy below your answer did.

Thanks

1 Like

Nice, I finally undestart why. Thanks

1 Like

I thought that, too

1 Like

Amazing. I learned today that split has a second optional paramer

I faced the same problem, removing the right whitespaces from the test cases solves it.
``````A = list(map(int, input().rstrip().split(' ')))