I am trying to use the python field calculator in ArcMap to do a simple calculation, where:
- there are two input variables, the numerator and the denominator
- if the numerator is zero a zero is returned
- else, the numerator is divided by the denominator and multiplied by 100
The code I tried:
def getScore(num, den):
if num == 0:
return 0
else:
return (num/den) * 100
when I run the script i get no errors yet the 'else' statement is not getting returned.
there will be no zeros in the denominator, so div/0 will not be an issue. The input fields are all 'long' integers and the target field is a 'double.'
I've attached a couple of images showing a test in python where the same exact code works perfectly, as well as the the field calculator where it does not work.