Runtime error - NZEC

Non zero error code (NZEC) is an error that usually occurs in programming contests or online coding platforms. In Python, runtime error – NZEC occurs when a program terminates with a non zero status code. The program returns a status code 0 if it executes successfully. It returns non zero status codes when it fails to execute. This non zero status code is referred to as runtime error - NZEC. Below we can see the flow chart illustrating how this error occurs:

Runtime error - NZEC
Runtime error - NZEC

In this Answer, we will see the reasons for runtime error – NZEC and how we can fix them.

Reasons for errors

We can come across runtime error - NZEC in various scenarios. Some common exceptions that can lead to NZEC errors are enlisted below:

  • ZeroDivisionError: Raised when dividing a number by zero.

  • IndexError: Raised when accessing an index out of range in a sequence.

  • NameError: Raised when trying to access a variable or name that has not been defined.

  • TypeError: Raised when performing unsupported operations between incompatible data types.

  • ValueError: Raised when a function receives an argument of the correct type but an inappropriate value.

  • RecursionError: Raised when a recursive function exceeds the maximum recursion depth.

Below we can see the coding examples showing the errors mentioned above:

ZeroDivisionError

Click the "Run" button to see the ZeroDivisionError:

a = 25
b = 0
result = a / b # Raises ZeroDivisionError: division by zero
print(result)
ZeroDivisionError exception raised

Code explanation

  • Line 3: We divide a with b, which raises the ZeroDivisionError because b contains 0 as its value.

IndexError

Click the "Run" button to see the IndexError:

lst = [1, 2, 3]
print(lst[3]) # Raises IndexError: list index out of range
IndexError exception raised

Code explanation

  • Line 2: We try to access an element at index 3, which raises the IndexError: list index out of range error.

NameError

Click the "Run" button to see the NameError:

x = 5
print(variable) # Raises NameError: name 'variable' is not defined
NameError exception raised

Code explanation

  • Line 2: We try to print variable that does not exist in our code which raises NameError: name variable is not defined error.

TypeError

Click the "Run" button to see the TypeError:

num = 5
text = "Hello"
result = num + text # Raises TypeError: unsupported operand type(s) for +: 'int' and 'str'
TypeError exception raised

Code explanation

  • Line 3: We try to concatenate two variables containing the string Hello and the other with integer value 5. Concatenating two different data types is not possible. Therefore, Python raises the `TypeError: unsupported operand types for+: 'int' and 'str' error.

ValueError

Click the "Run" button to see the ValueError:

user_input = "Age"
age = int(user_input)
ValueError exception raised

Code explanation

  • Line 2: We try to convert user_input into an integer data type which is not possible as Age cannot be converted to an integer data type. If user_input had a string value of any number like '1', '2', or any other number, then the program would execute successfully.

RecursionError

Click the "Run" button to see the RecursionError:

def infinite_recursion(n):
if n==1:
return
else:
infinite_recursion(n+1)
infinite_recursion(2) # Raises RecursionError: maximum recursion depth exceeded
RecursionError: maximum recursion depth exceeded in comparison

Code explanation

  • Lines 1–7: We define the infinite_recursion recursive function that return if n has a value of 1. We make a call to function at line 7 with n equal to 2. The function increments the value of n by 1 because of which, the base case, i.e., n==1 never reaches. This raises the RecursionError: maximum recursion depth exceeded in comparison error.

Conclusion

NZEC (non zero exit code) is not a specific error; rather, it is encountered in programming contests and online coding platforms when a program terminates with a non zero exit status code. The exact error message and the specific exception raised depend on the nature of the error in the code.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved