Python NZEC Runtime Error

import sys
num = int(sys.stdin.readline())
while (num != 42):
sys.stdout.write(num)
num = sys.stdin.readline()

Why does the above code give an NZEC runtime error?

3 Likes

it’s because the file used to feed the standard input has an end (as every file actually). when you try to read something without considering maybe there’s no data to read anymore, Python raises an exception and you get NZEC by the online judge. it could also come from the fact that, maybe the data you read cannot be converted to an integer, but if i remember well the problem you’re talking about, the input data should be consisting only of integers, so it’s not the glitch here. last thing, why not using raw_input() and print(), instead of sys.stdin.read() and sys.stdout.write() ?

5 Likes

n=int(input());
maxdif=-1;
for i in range(n):
a=int(input());
b=int(input());
if abs(a-b)>maxdif:
if a>b:
win=1;
maxdif=a-b;
else:
win=2;
maxdif=b-a;
print win, maxdif
this program is giving me a Nez runtime error can anyone help me out ???..

1 Like

def f():
x = int(raw_input())
y = float(raw_input())
s = 0
if x % 5 == 0:

    if x <= y:
        s = y - x - 0.50
        print s

    else:
        print y

else:
    print y

f()

def home():

x=[]

for number in range(0,4):

value = int(input('Enter the values for %dth element'%number))
x.append(value)

if x[2] - x[0] > 0 and x[1] - x[3] == 0:

print ('right')

elif x[0] - x[2] > 0 and x[1] - x[3] == 0:

print('left')

elif x[0]-x[2] == 0 and x[1] - x[3] > 0 :

print ('down')

elif x[0] - x[2] == 0 and x[3] - x[1] > 0 :

print ('up')

else :

print (‘sad’)

test_case= int(input(‘Enter the number of test cases’))

for no in range(0,test_case):

home()

I’m getting NZEC Error for this code. Someone please help! Thanks in advance

w = input()

print(w)

I am getting an nzec error for this code on the chef compiler, not IDLE

@srirammurali91 Make sure you are using Python 3.5 on codechef,using Python 2 will give NZEC as syntax for Python 2 is different.

2 Likes

I am getting NZEC on this, however it works fine in IDLE:

z=0
e=0
l=0
r=0
lis=[]
poss=[]
data=[]
times=input()

def getDay(n):
    if(n=="sunday"):
        s=0
    elif(n=="monday"):
        s=1
    elif(n=="tuesday"):
        s=2
    elif(n=="wednesday"):
        s=3
    elif(n=="thursday"):
        s=4
    elif(n=="friday"):
        s=5
    elif(n=="saturday"):
        s=6

    return s
    
for i in range(0,int(times)):
    data=input().split()

    z=(getDay(data[0]))
    e=(getDay(data[1]))
    l=(int(data[2]))
    r=(int(data[3]))
      
    for j in range(1,15):
        lis.append((7*j+e)-z+1)

    for j in lis:
        if(j>=l and j<=r):
            poss.append(j)

    if(len(poss)==0):
        print("impossible")
    elif(len(poss)==1):
        print(poss[i])
    else:
        print("many")
        
    list=[]
    poss=[]

Your suggestion to use raw_input() and print(), instead of sys.stdin.read() and sys.stdout.write() solved my problem.
Thank you!

last line should be num = int(sys.stdin.readline())

4 Likes

in your second option for print, poss[i] should be poss[0], probably.

I tried with the raw_input too… but not working …

test_case = input()
num = []
for i in range(test_case):
num.append(raw_input())

for i in num:
print next_palidro(i)

2 Likes

use:
temp = input()
a,b = temp.split(" ")
this will solve your problem as the first line of input i.e e.g if the input is 10 4
using a = input() will take the entire line as a string and not leave anything for b to take in input nad hence the problem

Hey I’m facing the same problem
My Code:
temp=input()
print(temp)
I’m using Python 3.6 still I’m getting NZEC. What should I do?

1 Like

Facing same issue in python 3.6 :
notc=input()
print(notc)
getting NZEC for above lines, really frustrating

I am also getting NZEC error when i am running below code.

num=[6,2,5,5,4,5,6,3,7,6]
t=int(input())
for i in range(t):
a,b=map(int,input().split())
c=a+b
count=0
while(c!=0):
rem=c%10
c/=10
count+=num[rem]
if(i!=n-1):
print(count)
else:
print(count,end=’’)

Can anyone please help me in correcting this error.

Please share your solution link or format your code correctly.
Use three backticks ``` before and after your code.

Example:

```
Code
```

Then it looks like:

num=[6,2,5,5,4,5,6,3,7,6]
t=int(input())
for i in range(t):
  a,b=map(int,input().split())
  c=a+b
1 Like

@ankitsinla In your code, you use undefined variable n
if(i != n - 1):

Hey I’m getting NZEC error in fir line i.e T=int(input())
Please Help

    T = int(input())
while T:
    T-=1
    N,M = map(int, input().strip().split(" "))
    f = list(map(int,input().strip().split(" ")))
    p = list(map(int,input().strip().split(" ")))
    arr = [0]*M
    for i in range(0,N):
        arr[f[i]] = arr[f[i]] + p[i]
    
    arr.sort()
    for j in arr:
        if j != 0:
            print(j,end="")
            break

Have you provided custom input?

1 Like