1

This question already has an answer here:

I have tried all of below snippets to use Python Parser in Field Calculator and update the values of a field called type based on a filed called MamerMN but in all of them I am getting Syntax error in Geoprocessing result window!

if !MamerMN! <= 0.151560:
    return 1

and

if (!MamerMN! <= 0.151560):
    return 1

and

if (MamerMN <= 0.151560):
    return 1

and

def(MamerMN)
if MamerMN <= 0.151560:
    return 1

and

def(MamerMN)
if (MamerMN <= 0.151560):
    return 1

Can you please let me know what I am doing wrong?

Update

def foo(MamerMN):
  if MamerMN <= 0.151560:
     return 1

marked as duplicate by PolyGeo Aug 18 '15 at 22:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • did you push the python radio button? – Brad Nesom Aug 18 '15 at 19:59
  • Are you placing this in the codeblock? You need to make sure you're using proper indentation as well. The last two are not proper python syntax either. it should be def foo(bar): return bar**bar – Paul Aug 18 '15 at 20:00
  • Yes Brad , I already did – Behseini Aug 18 '15 at 20:00
  • @Paul , can you please let me know what do you mean by codeblock? – Behseini Aug 18 '15 at 20:01
  • 1
    Ok, so if that is your code block then the expression should look like foo(!MamerMN!) – Paul Aug 18 '15 at 20:14
2

Thanks to Paul

Here is the solution: in Pre-logic Script Code Box:

def foo(MamerMN): 
  if (MamerMN <= 0.200000): 
     return 1
  elif (MamerMN >= 0.200001 and  MamerMN <= 0.400000):
     return 2
  elif (MamerMN >= 0.400001 and  MamerMN <= 0.600000):
     return 3
  elif (MamerMN >= 0.600001 and  MamerMN <= 0.800000):
     return 4
  elif (MamerMN >= 0.800001):
     return 5

and in Expression box

foo( !MamerMN! )

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