0

i'm a python beginner. I have a table with 4 fields def_score, PA_score, GPS_score and coop_score. I would like to calculate coop_score based on the first 3 fields with the following code block, but it's not working. Where am i wrong?

defor = 'def_score'
PA = 'PA_score'
GPS = 'GPS_score'   # GPS values are [1, 1.5, 2]

def calc(coop_score): 
    if PA == 0 and defor == 0: 
        return GPS 
    else: 
        return ((PA + defor) * GPS)

enter image description here

0

1 Answer 1

2

Try:

def calc(PA, defor, GPS): #The input fields here, not the output field. The field order need to be the same as when you call the function.
    if PA == 0 and defor == 0: 
        return GPS 
    else: 
        return ((PA + defor) * GPS)

Call with coop_score=

calc(!PA_score!,!def_score!,!GPS_score!) #You need the actual fieldnames here enclosed in !!

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.