# Python NZEC Runtime Error

**URL:** <https://discuss.codechef.com/t/python-nzec-runtime-error/107>\
**Category:** general\
**Tags:** error, nzec, python, rte, runtime\
**Created:** [April 22, 2012, 12:51am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107 "2012-04-22T00:51:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![veknilash](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@veknilash](https://discuss.codechef.com/u/veknilash)\
**Post date:** [April 22, 2012, 12:51am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/1 "2012-04-22T00:51:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cyberax](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@cyberax](https://discuss.codechef.com/u/cyberax)\
**Post date:** [April 22, 2012, 1:15am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/2 "2012-04-22T01:15:52Z")

</div>

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() ?

---

<div class="post-metadata">

**Author:** ![sharma16aug](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@sharma16aug](https://discuss.codechef.com/u/sharma16aug)\
**Post date:** [August 26, 2015, 8:15pm UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/3 "2015-08-26T20:15:59Z")

</div>

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 ???..

---

<div class="post-metadata">

**Author:** ![shubham\_0007](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@shubham\_0007](https://discuss.codechef.com/u/shubham_0007)\
**Post date:** [November 17, 2015, 10:59am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/4 "2015-11-17T10:59:37Z")

</div>

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()

---

<div class="post-metadata">

**Author:** ![themitigater](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@themitigater](https://discuss.codechef.com/u/themitigater)\
**Post date:** [April 9, 2017, 2:45am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/5 "2017-04-09T02:45:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![srirammurali91](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@srirammurali91](https://discuss.codechef.com/u/srirammurali91)\
**Post date:** [May 31, 2018, 1:41am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/6 "2018-05-31T01:41:13Z")

</div>

w = input()

print(w)

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

---

<div class="post-metadata">

**Author:** ![pj21](https://discuss.codechef.com/user_avatar/discuss.codechef.com/pj21/32/3653_2.png) [@pj21](https://discuss.codechef.com/u/pj21)\
**Post date:** [May 31, 2018, 1:52am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/7 "2018-05-31T01:52:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aditya\_arsh1](https://discuss.codechef.com/user_avatar/discuss.codechef.com/aditya_arsh1/32/29107_2.png) [@aditya\_arsh1](https://discuss.codechef.com/u/aditya_arsh1)\
**Post date:** [November 25, 2018, 7:42pm UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/8 "2018-11-25T19:42:25Z")

</div>

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=[]
```

---

<div class="post-metadata">

**Author:** ![veknilash](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@veknilash](https://discuss.codechef.com/u/veknilash)\
**Post date:** [April 22, 2012, 1:32am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/9 "2012-04-22T01:32:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![r3gz3n](https://discuss.codechef.com/user_avatar/discuss.codechef.com/r3gz3n/32/103816_2.png) [@r3gz3n](https://discuss.codechef.com/u/r3gz3n)\
**Post date:** [September 5, 2013, 2:47pm UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/10 "2013-09-05T14:47:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joffan](https://discuss.codechef.com/user_avatar/discuss.codechef.com/joffan/32/333411_2.png) [@joffan](https://discuss.codechef.com/u/joffan)\
**Post date:** [November 26, 2018, 2:29am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/11 "2018-11-26T02:29:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rahulshah9191](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@rahulshah9191](https://discuss.codechef.com/u/rahulshah9191)\
**Post date:** [May 24, 2019, 9:45am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/12 "2019-05-24T09:45:39Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![mazharalibaig](https://discuss.codechef.com/user_avatar/discuss.codechef.com/mazharalibaig/32/3653_2.png) [@mazharalibaig](https://discuss.codechef.com/u/mazharalibaig)\
**Post date:** [July 6, 2019, 6:51am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/13 "2019-07-06T06:51:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rishi132](https://discuss.codechef.com/user_avatar/discuss.codechef.com/rishi132/32/3653_2.png) [@rishi132](https://discuss.codechef.com/u/rishi132)\
**Post date:** [August 4, 2019, 2:56pm UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/14 "2019-08-04T14:56:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jiteshnc17](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@jiteshnc17](https://discuss.codechef.com/u/jiteshnc17)\
**Post date:** [September 14, 2019, 5:34pm UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/15 "2019-09-14T17:34:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ankitsinla](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ankitsinla/32/3653_2.png) [@ankitsinla](https://discuss.codechef.com/u/ankitsinla)\
**Post date:** [September 23, 2019, 3:08pm UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/16 "2019-09-23T15:08:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![smile\_forever](https://discuss.codechef.com/user_avatar/discuss.codechef.com/smile_forever/32/299669_2.png) [@smile\_forever](https://discuss.codechef.com/u/smile_forever)\
**Post date:** [September 23, 2019, 6:42pm UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/17 "2019-09-23T18:42:50Z")

</div>

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

**Example:**

```  
Code  
```

Then it looks like:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![smile\_forever](https://discuss.codechef.com/user_avatar/discuss.codechef.com/smile_forever/32/299669_2.png) [@smile\_forever](https://discuss.codechef.com/u/smile_forever)\
**Post date:** [September 23, 2019, 6:49pm UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/18 "2019-09-23T18:49:46Z")

</div>

> [@ankitsinla](#):
>
> if(i!=n-1):

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

---

<div class="post-metadata">

**Author:** ![rohit\_vish18](https://discuss.codechef.com/user_avatar/discuss.codechef.com/rohit_vish18/32/19115_2.png) [@rohit\_vish18](https://discuss.codechef.com/u/rohit_vish18)\
**Post date:** [March 8, 2020, 7:48am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/19 "2020-03-08T07:48:07Z")

</div>

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

```auto
    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

```

---

<div class="post-metadata">

**Author:** ![everule1](https://discuss.codechef.com/user_avatar/discuss.codechef.com/everule1/32/24644_2.png) [@everule1](https://discuss.codechef.com/u/everule1)\
**Post date:** [March 8, 2020, 7:51am UTC](https://discuss.codechef.com/t/python-nzec-runtime-error/107/20 "2020-03-08T07:51:40Z")

</div>

Have you provided custom input?

[Next page](https://discuss.codechef.com/t/python-nzec-runtime-error/107.md?page=2)
