I'm new to Python/VB Script and am needing some help. I have tried several different If/Then statements but can't seem to get it straight. I am hoping for some help. I have 3 fields. ZONING, SQFeet_1, and Buildout. Depending on the Value of the ZONING field, will depend on what formula I need to use. For instance, if ZONING = RS6 then I need to use the formula (SQFeet_1/6000*.80) or if ZONING = SP then I need to use the formula (SQFeet_1/2000*.80), etc... How would I write the IF/Then statement to get the results? Or would I need to use a different statement?
1 Answer
Best go is use of dictionary:
def getDivider(A,B):
aDict={'RS6':6000,'SP':2000}
if A in aDict: return B/aDict[A]*0.8
return -1
======================================
getDivider(!ZONING!,!SQFeet_1!)
Update following @Paul suggestion:
def getDivider(A,B):
aDict={'RS6':6000,'SP':2000}
return B/aDict.get(A,0)*0.8
-
-
-
1A different approach would be
return B/aDict.get(A, 0)*0.8
where 0 is a value you want returned when a value can't be found in the dict (aka, the default value). No need to check if the key is present.– PaulCommented Mar 28, 2016 at 21:47 -
-
Thanks guys, I'm going to try this out today and will get back with ya'll! Commented Mar 29, 2016 at 12:53