numbers = IN[0]
divisor = IN[1]
def divide(x, y):
try:
result = x / y
except ZeroDivisionError:
return (0.00)
else:
return(result)
finally:
return(result)
result = []
for i in divide(numbers,divisor):
result.append(i)
OUT = result
Have you tried declaring local variable result before assigning something?
numbers = IN[0]
divisor = IN[1]
def divide(x, y):
result = 0
try:
result = x / y
except ZeroDivisionError:
return (0.00)
else:
return(result)
finally:
return(result)
result = []
for i in divide(numbers,divisor):
result.append(i)
OUT = result
numbers = IN[0]
divisor = IN[1]
result = []
def divide(x, y):
try:
global result
result = x / y
except ZeroDivisionError:
return (0.00)
else:
return(result)
finally:
return(result)
final = []
for i in divide(numbers,divisor):
final.append(i)
OUT = final
The super class of ZeroDivisionError is ArithmeticError. This exception raised when the second argument of a division or modulo operation is zero. In Mathematics, when a number is divided by a zero, the result is an infinite number. It is impossible to write an Infinite number physically. Python interpreter throws “ZeroDivisionError: division by zero” error if the result is infinite number. While implementing any program logic and there is division operation make sure always handle ArithmeticError or ZeroDivisionError so that program will not terminate.