NZEC error in Python?


NZEC is non-zero exit code.

Exit codes are codes (number) return by running program to operating system upon either their successfully termination (Exit code 0) or failed termination due to error (Non zero exit code).

As python or Java programming language supports exception handling, we can use exception handling using try-catch blocks to catch this error.

NZEC error is a runtime error and occurs mostly when negative array index is accesed or the program which we have written is utilizing more memory space than the allocated memory for our program to run.

In python Exception class is the super class of all the errors and exceptions.

We can use below code sample

try:
   #Code that may throw an error
except Exception, e:
   pass

Example 1

Wrong way −

x,y = map(int, input())

correct way −

x,y = map(int, input().split())

to delimit input by white spaces:

Possible reason of getting NZEC error:

  • Infinite Recursion – or if you are run out of stack memory.

  • Make sure your input and output both are exactly same as the test cases. It is advisable to test your program using a computer code which matches your output with the specified outputs exactly.

  • Another common reason of getting this error is when you make basic programming mistakes lik dividing by 0.

  • Check for the values of your variables, they can be vulnerable to integer flow.

  • Directly trying to compute factorial above 20, if you are – find another way to do that.

Generally competitive programming platform like codechef do not give the error code, so you yourself have to debug your code. Check for edge cases(corner cases), make sure you are not making any mistakes mentioned above.

Example 2

Bad way:

for i in range(0,n):
   x=int(input())
   arr.append(x)

Correct way:

arr = [int(k) for k in input().split()]

OR

arr = list(map(int, input().split()))

Updated on: 30-Jul-2019

641 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements