1

I am trying to populate a field with a text string based on a combination of two other fields. The field !yearsSinceAct! is a decimal (float) of years. !OperationalStatus! is a text field describing whether or not a particular feature is operable or not. The three options for !OperationalStatus! are "OK", "Inoperable", and null

actionRating =
Reclass(!yearsSinceAct!,!OperationalStatus!)
def Reclass(Rating,Operation):
 if (Rating <= 1) and (Operation = "OK"):
 return "Recently operated or serviced"
 elif (1 < Rating <= 5) and (Operation = "OK"):
 return "Operated or serviced between 1 and 5 years ago"
 elif (Rating > 5) and (Operation = "OK"):
 return "Last known to be OK but no promises; it's been a minute"
 elif (Rating <= 1) and (Operation = "Inoperable"):
 return "Recently found to be non-functioning"
 elif (1 < Rating <= 5) and (Operation = "Inoperable"):
 return "Found to be dysfunctional and has not been repaired in 1-5 years"
 elif (Rating > 5) and (Operation = "Inoperable"):
 return "This valve has been left in the dust"
 else:
 return "Unknown"

I can't get this code block to work. I tried assigning the outputs to a variable and then returning that variable at the end too with no success. Any ideas?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Mar 6 at 14:16
0

1 Answer 1

4

According to Comparisons - Built-in Types - Python 3.x documentation:

This table summarizes the comparison operations:

Operation Meaning
< strictly less than
<= less than or equal
> strictly greater than
>= greater than or equal
== equal
!= not equal
is object identity
is not negated object identity

The existing code is using a single equals sign, which is an assignment statement. What is needed is two equal signs, which is an equality comparison.

answered Mar 7 at 15:00

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.