2

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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 17, 2016 at 22:48

1 Answer 1

4

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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Jul 17, 2016 at 22:57
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.