I'm trying to work out how to populate a field depending on the lowest score across 6 other fields. I've read several other questions relating to if/else statements but I'm only just starting to learn Python so I'm struggling to put together any code that works.
I'm trying to populate a 'Main Failing' field, where for each object ID in the feature class the worst scored field out of 6 other fields will be noted.
The other fields are: 'Interconnectivity', 'PropCover', 'PatchSize', 'ShapeIndex', 'Naturalness' and 'EdgeNat' and they are all short integer, with high numbers being better than low numbers.
So for example if 'Interconnectivity' had the lowest score across the 5 fields for one objectID, I would like to work out how to populate the 'Main Failing' column for that objectID with text saying 'Interconnectivity'.
Edited: Here's an example of the code I've tried so far with Branco's help. It's running without errors but is either leaving the MainFailing field blank (if 'return resultList[0]') or is populating it with 0's (if return resultList[1]).
Codeblock:
myFunction( !InterconnectivityScore!, !PropCoverScore!, !PatchSizeScore!, !ShapeIndexScore!, !NatScore!, !EdgeNatScore!)
Pre-logic script code:
def myFunction ( interconnectivityScoreValue, propCoverScoreValue, patchSizeScoreValue, shapeIndexScoreValue, natScoreValue, edgeNatScoreValue):
resultList = ["",0]
if interconnectivityScoreValue <= resultList[1]:
resultList[0] = "Interconnectivity"
resultList[1] = InterconnectivityScore
if propCoverScoreValue <= resultList[1]:
resultList[0] = "ProportionalCover"
resultList[1] = PropCoverScore
if patchSizeScoreValue <= resultList[1]:
resultList[0] = "PatchSize"
resultList[1] = PatchSizeScore
if shapeIndexScoreValue <= resultList[1]:
resultList[0] = "ShapeIndex"
resultList[1] = ShapeIndexScore
if natScoreValue <= resultList[1]:
resultList[0] = "Naturalness"
resultList[1] = NatScore
if edgeNatScoreValue <= resultList[1]:
resultList[0] = "EdgeNaturalness"
resultList[1] = EdgeNatScore
return resultList[1]