Change language

NZEC error in Python

| |

While coding on various competing sites, many people must have encountered the NZEC error. NZEC (non-zero exit code), as the name suggests, occurs when your code cannot return 0. When the code returns 0, it means it succeeded, otherwise it will return some other number depending on the type of error. 
When the program exits and is expected to return "0" to indicate that everything ran fine and is unable to do so, it calls NZEC. Of course, there are more NZEC-related cases.

Why is NZEC happening? (One example)

In python, typically multiple inputs are separated by commas and we read them using input () or int (input ()), but most online coding platforms during testing is given a space-separated input and in these cases int (input ()) cannot read the input correctly and shows an error like NZEC.

How to solve?

For example, imagine a simple program in which you have to read 2 integers and print them (in the input file, both integers are on the same line). Suppose you have two integers like below:
23 45
Instead of using:

 n = int (input ()) k = int (input ( )) 

Usage:

 n, k = raw_input (). split ("") n = int (n) k = int (k) 

limit input to spaces.

Invalid code

n = int ( input ())

k = int ( input ( ))

print n, "" , k

Input data :
2 3
When you run the above code in the IDE with the above input, you will get an error: —

 Traceback (most recent call last): File "b712edd81d4a972de2a9189fac8a83ed.py", line 1, in n = int (input ()) File "", line 1 2 3 ^ SyntaxError: unexpected EOF while parsing 

The above code will work well when the input is on two different lines. You can test yourself. To overcome this problem, you need to use split.

Correct code

n, k = raw_input (). split ( "" )

n = int (n)

k = int (k)

print n, "" , k

Input data :

 7 3 

Output:

 7 3 

Some important causes of the NZEC error

  1. Infinite recursion or if you run out of stack memory.
  2. The input and output are NOT exactly the same as the test cases.
  3. As an online platform, test your program using computer code that matches your exact output with specified outputs
  4. This type of error is also displayed when your program makes major programming errors such as division by 0.
  5. Check the values ​​of your variables, they might be vulnerable to an integer stream .

There may be other causes of the NZEC error, I have listed common ones.

This article is provided by Aakash Tiwari . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting the article [email protected] ... See my article appearing on the Python.Engineering homepage and help other geeks.

Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically