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?
-
If [ZONING] = 'RS6': Then (SQFeet_1/6000*.80) Elif [ZONING] = 'SP': Then (SQFeet_1/2000*.80)Kevin Cross– Kevin Cross2016-03-28 20:10:52 +00:00Commented Mar 28, 2016 at 20:10
-
1You should add that code to your question, users here like to see the effort you've put in so far.Dan C– Dan C2016-03-28 20:20:33 +00:00Commented Mar 28, 2016 at 20:20
Add a comment
|
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
-
why should the function return -1?ziggy– ziggy2016-03-28 19:37:42 +00:00Commented Mar 28, 2016 at 19:37
-
To answer this read line aboveFelixIP– FelixIP2016-03-28 19:48:45 +00:00Commented Mar 28, 2016 at 19:48
-
1A different approach would be
return B/aDict.get(A, 0)*0.8where 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.Paul– Paul2016-03-28 21:47:41 +00:00Commented Mar 28, 2016 at 21:47 -
@Paul very nice, will make it even shorterFelixIP– FelixIP2016-03-28 22:13:23 +00:00Commented Mar 28, 2016 at 22:13
-
Thanks guys, I'm going to try this out today and will get back with ya'll!Kevin Cross– Kevin Cross2016-03-29 12:53:19 +00:00Commented Mar 29, 2016 at 12:53
