I don't know a whole lot about python and scripting, so I was hoping somebody could give me a couple pointers on fixing some code. I am trying to calculate a "final results" attribute field. The field type is numeric, because I want the values to either be a 1 (pass) or 0 (fail). Below are two variations of the code I have tried, but they both give me errors. The two fields I am trying to calculate from are both text fields, and the values for both are either "PASS" or "FAIL."enter image description here enter image description here

  • 2
    What was the error? You also seem to be returning strings, not numbers. Dec 11, 2014 at 20:12

3 Answers 3


In general your condition statement should go as:

if TEST1 == 'FAIL':
    return 0

Single or double quotes for checking fields with string values, and when returning to a numeric field no quotes needed.


If I'm reading your logic correctly, if either Test1 or Test2 = FAIL, you want to return 0, but if both = PASS you want to return 1. I'd do something like this:

def Final(t1, t2):
    if t1 == 'FAIL' or t2 == 'FAIL':
        val = 0
    elif t1 == 'PASS' and t2 == 'PASS':
        val = 1
        val = 2   # this allows you to check if t1 or t2 had some other value
    return val

You could use a dict structure ({key: value}) to convert keywords like PASS to the standard bool type (i.e., True and False). After this conversion to bool, it is conventional logic:

def Final(t1, t2):
    c = {'PASS': True, 'FAIL': False}
    t1 = c[t1]
    t2 = c[t2]
    if t1 and t2:
        return 1
        return 0

Note that if you have other test values like GOOD or Pass, you will see a KeyError, so you can extend the dict structure, if necessary, to other synonyms that are either True or False.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.