I have 3 fields in a table that i need to evaluate and return a new value based on the results using the field calculator (PYTHON)
They are: SETSPAID (long) This field must = 0 TYPEOFSERVICE (string) This field must = 1 or 3 STATUS (double) This field can not be 5 or 6
Here is what I have so far:
Pre-logic Script Code:
def calc(f1,f2,f3,f4,f5,f6,f7,f8):
if f4 == f5 and (f1 == f2 or f1 == f3) and (f6 != f7 or f6 != f8):
return 1
else:
return f4
SETSPD =
calc(!TYPEOFSERVICE!, '1', '3', !SETSPAID!, 0, !STATUS!, 5, 6)
When I run this code, it still assigns a 1 when status is 6. Not sure what im doing wrong.
1 Answer 1
In your if
line you need to change your or
to an and
in the last part.
if f4 == f5 and (f1 == f2 or f1 == f3) and (f6 != f7 and f6 != f8):
This is because with f6 != f7
(6 != 5
) it returns 1, even though f6 != f8
fails (6 = 6
) in the second part. With the OR
there it returns true if one of them is true. With an AND
it would return true only if both are true.
Explore related questions
See similar questions with these tags.