Search code examples
pythonif-statementcalculatorarcgisarcmap

Indentation errors with code block?


I tried to define the following functions, but I keep getting:
error 000989 : Python syntax error: <value>.

So apparently my code has improper syntax. I've tried the following:

def yieldCalc(value):
 if (value=1):
     return 6.2
  elif (value=2):
     return 7.9
  else:
     return 8.21

Also

def yieldCalc(value):
 if (value=1):
     return 6.2
  elif (value=2):
     return 7.9
 else:
     return 8.21

And

def yieldCalc(value):
 if (value=1):
     return 6.2
 elif (value=2):
     return 7.9
 else:
     return 8.21

What is the proper way to indent the python code block?


Solution

  • in python you should use double equal signs == to compare two values:

    def yieldCalc(value):
        if value == 1:
            return 6.2
        elif value == 2:
            return 7.9
        else:
            return 8.21
    

    Please see the following links from python's documentation for more information on indentation and comparisons:

    Style Guide - Indentation

    Built-in types - Comparison