Introduction
As a programmer, you must have come across the NZEC error at least once. Most of you might have seen it in online coding platforms.
Exit codes are numbers returned by running programs to the operating system upon successful termination of the program. If the program terminated successfully without any error, exit code 0 is returned.
However, in case of any other situation where there was a problem in the successful termination of the program, a Non Zero Exit Code is returned. This is known as the NZEC Error.
In this article, we shall discuss the Non Zero Exit Code, the reason for NZEC, and the ways we can resolve it.
Also See, Divmod in Python, Fibonacci Series in Python
Reason for NZEC Error
There can be various reasons for NZEC errors. We shall now see most of them one by one with code examples.
Read More, python packages
Infinite recursion
Because of infinite recursion, we will run out of stack memory, and the program will throw an error.
Example:
i=1
# recursive function to print Coding Ninjas
def recursiveFunc():
print("Coding Ninjas")
if i>0:
recursiveFunc()
# calling the recursiveFunc
recursiveFunc()
Output:
Also see, Merge Sort Python and Convert String to List Python.
Wrong Way of Input/Output
This is one of the biggest reasons for NZEC to occur. In most coding platforms, you are required to input N space-separated integers. Failing to do so in an appropriate manner will result in NZEC error.
Example:
We have to input three space-separated integers 1 2 3.
# we need to input three space-separated integers
# 1 2 3
# incorrect way
firstNum = int(input())
secondNum = int(input())
thirdNum = int(input())
print( firstNum)
print( secondNum)
print( thirdNum)
Output:
Dividing by 0
Dividing any number by zero will result in NZEC error
Example:
# dividing by zero
x= 5/0
print(x)
Output:
You can try it on online python compiler.
Accessing Wrong Index
Example:
# Accessing the Wrong Index
my_list=["Coding", "Ninjas", "Blogs"]
# prints Coding
# print(my_list[0])
# prints Ninjas
# print(my_list[1])
# accessing index 5, which is more than the size of my_list
print(my_list[5])
Output: