The Wayback Machine - https://web.archive.org/web/20240626172716/https://www.geeksforgeeks.org/nzec-error-python/
Open In App

NZEC error in Python

Last Updated : 16 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

While coding in various competitive sites, many people must have encountered NZEC errors. NZEC (non zero exit code) as the name suggests occurs when your code is failed to return 0. When a code returns 0 it means it is successfully executed otherwise it will return some other number depending on the type of error. When the program ends and it is supposed to return “0” to indicate if finished fine and is not able to do so it causes NZEC. Of course, there are more cases associated with NZEC.

Why does NZEC occur?(one example)

In python, generally, multiple inputs are separated by commas and we read them using input() or int(input()), but most of the online coding platforms while testing give input separated by space and in those cases, int(input()) is not able to read the input properly and shows error like NZEC.

How to resolve?

For Example, Think of a simple program where you have to read 2 integers and print them(in the input file both integers are in same line). Suppose you have two integers as shown below: 23 45 Instead of using :

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

Use:

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

to delimit input by white spaces.

Wrong code

Python




n = int(input())
k = int(input())
print(n," ",k)


Input: 2 3

 When you run the above code in IDE with the above input you will get 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 fine when the input is in 2 two different lines. You can test yourself. To overcome this problem you need to use split.

Correct code

Python




n,k=input().split()
n = int(n)
k = int(k)
print(n," ",k)


Input:

7 3

Output:

7   3

Some prominent reasons for NZEC error

  1. Infinite Recursion or if you have run out of stack memory.
  2. Input and output are NOT exactly same as the test cases.
  3. As the online platforms, test your program using a computer code which matches your output with the specified outputs exactly.
  4. This type of error is also shown when your program is performing basic programming mistakes like dividing by 0.
  5. Check for the values of your variables, they can be vulnerable to integer flow.

There could be some other reasons also for the occurrence NZEC error, I have listed the frequent ones.


Similar Reads

Python Value Error :Math Domain Error in Python
Errors are the problems in a program due to which the program will stop the execution. One of the errors is 'ValueError: math domain error' in Python. In this article, you will learn why this error occurs and how to fix it with examples. What is 'ValueError: math domain error' in Python?In mathematics, we have certain operations that we consider un
4 min read
How to Navigating the "Error: subprocess-exited-with-error" in Python
In Python, running subprocesses is a common task especially when interfacing with the system or executing external commands and scripts. However, one might encounter the dreaded subprocess-exited-with-error error. This article will help we understand what this error means why it occurs and how to resolve it with different approaches. We will also p
4 min read
True Error vs Sample Error
True Error The true error can be said as the probability that the hypothesis will misclassify a single randomly drawn sample from the population. Here the population represents all the data in the world. Let's consider a hypothesis h(x) and the true/target function is f(x) of population P. The probability that h will misclassify an instance drawn a
3 min read
Python | Prompt for Password at Runtime and Termination with Error Message
Say our Script requires a password, but since the script is meant for interactive use, it is likely to prompt the user for a password rather than hardcode it into the script. Python’s getpass module precisely does what it is needed. It will allow the user to very easily prompt for a password without having the keyed-in password displayed on the use
3 min read
Python | Mean Squared Error
The Mean Squared Error (MSE) or Mean Squared Deviation (MSD) of an estimator measures the average of error squares i.e. the average squared difference between the estimated values and true value. It is a risk function, corresponding to the expected value of the squared error loss. It is always non – negative and values close to zero are better. The
2 min read
Python | Assertion Error
Assertion Error Assertion is a programming concept used while writing a code where the user declares a condition to be true using assert statement prior to running the module. If the condition is True, the control simply moves to the next line of code. In case if it is False the program stops running and returns AssertionError Exception. The functi
3 min read
Python IMDbPY - Error Handling
In this article we will see how we can handle errors related to IMDb module of Python, error like invalid search or data base error network issues that are related to IMDbPY can be caught by checking for the imdb.IMDbErrorexceptionIn order to handle error we have to import the following from imdb import IMDbError Syntax : try : # code except IMDbEr
2 min read
How to print the Python Exception/Error Hierarchy?
Before Printing the Error Hierarchy let's understand what an Exception really is? Exceptions occur even if our code is syntactically correct, however, while executing they throw an error. They are not unconditionally fatal, errors which we get while executing are called Exceptions. There are many Built-in Exceptions in Python let's try to print the
3 min read
Create Error Bars in Plotly - Python
Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library. Error Bars in Plotly For functions representing
3 min read
Error Handling in Python using Decorators
Decorators in Python is one of the most useful concepts supported by Python. It takes functions as arguments and also has a nested function. They extend the functionality of the nested function. Example: C/C++ Code # defining decorator function def decorator_example(func): print("Decorator called") # defining inner decorator function def
2 min read
Practice Tags :
three90RightbarBannerImg