# Calculate field value based on lat long. Have longitude values which are negative?

Very new to python, fairly experienced with ArcMap. I am trying to create an alphanumeric index based on point locations

My code string for the numeric part is here:

``````def calc(!LONG_x!):

if !LONG_x! >= -113.90550 and !LONG_x! <= -113.90559:
return "05"
else:
return "0"
``````

I continue to get an error 000989 for syntax. What am I doing wrong?

You can't use punctuation marks in variable names in python. Your function should probably read more like this:

``````def calc(LONG_x):
if LONG_x >= -113.90550 and LONG_x <= -113.90559:
return "05"
else:
return "0"
``````

You can then pass in !LONG_x! as an argument to the function.

eg. result = calc(!LONG_x!)

• BruceDoh, That solved it. Thank you. I have Magnus Hetland's beginning python book. Does one find these syntax answers somewhere within its pages? Jul 21, 2015 at 18:09
• Right, I think the !FieldName! notation is specific to ArcGIS and isn't strictly Python proper. Magnus probably says somewhere in the book that variable names can only have letters, numbers, and underscores (no special characters) and can't begin with a number.
– John
Jul 21, 2015 at 20:24
• When solved, it is good idea to mark it as solved Jul 21, 2015 at 21:54
• And how do I mark it as solved? Jul 22, 2015 at 20:00
• Click the checkmark button under the up and down arrows. Jul 22, 2015 at 20:01