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?

enter image description here

  • If [ZONING] = 'RS6': Then (SQFeet_1/6000*.80) Elif [ZONING] = 'SP': Then (SQFeet_1/2000*.80) – Kevin Cross Mar 28 '16 at 20:10
  • 1
    You should add that code to your question, users here like to see the effort you've put in so far. – Dan C Mar 28 '16 at 20:20

Best go is use of dictionary:

def getDivider(A,B):
    if A in aDict:  return B/aDict[A]*0.8
    return -1



Update following @Paul suggestion:

def getDivider(A,B):
  return B/aDict.get(A,0)*0.8
  • why should the function return -1? – ziggy Mar 28 '16 at 19:37
  • To answer this read line above – FelixIP Mar 28 '16 at 19:48
  • 1
    A 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. – Paul Mar 28 '16 at 21:47
  • @Paul very nice, will make it even shorter – FelixIP Mar 28 '16 at 22:13
  • Thanks guys, I'm going to try this out today and will get back with ya'll! – Kevin Cross Mar 29 '16 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.