Nested If Else Python Script

07-08-2014 06:32 AM
New Contributor II
0 0 1,673

I am thoroughly confused by the new format of the forums, so I hope I am posting this correctly and that I am in the right space.

I have a python script I am trying to write for a field calculator in ArcGIS 10.2.  The field [fclass] is a numeric field with the numbers 1, 2, 6, 7, 8, 9, 11, 12 ,14 ,16, 17, and 19.  These correspond to different road levels.

I have created a float field [Speed] and I am trying to assign each row a speed based on the fclass.  Thus if the code is 1 or 11 (interstate highways) the value should be 55, 9 or 19 (local roads) and it would be 25 etc. 

I am sure I am way off, but I got a basic version of the following script to work.

In the Python codeblock

def myCalc(fclass,fclassVal):

if (fclass == fclassVal):

  return 55


  return 25

in the calculate field



However, this of course simply changes the fclass of 1 to 55 and makes the rest all 25.  If somebody could give me an idea how to write a "nested" statement I would greatly appreciate it.

Again, sorry if this is the wrong space for the question, but this new forum design is really weird.

Tags (2)