# Field Calculator and Python If statement

Question asked by ccowin on Apr 6, 2020
Latest reply on Apr 7, 2020 by JMutunga-esristaff

Hi,

Trying to replicate the code from this guide: Calculate Field Python examples—Data Management toolbox | Documentation

Which is:

Expression:

Reclass(!WELL_YIELD!)

Code Block:

def Reclass(WellYield):

if (WellYield >= 0 and WellYield <= 10):

return 1

elif (WellYield > 10 and WellYield <= 20):

return 2

elif (WellYield > 20 and WellYield <= 30):

return 3 elif (WellYield > 30):

return 4

My Code:

Expression:

Reclass(!Id!)

Code Block

def Reclass(Level):
if (Id >= 0 and Id <= 10):
return 1
elif (Id > 10 and Id <= 20):
return 2
elif (Id > 20 and Id <= 30):
return 3
elif (Id > 30 and Id <= 40):
return 4
elif (Id > 40 and Id <= 50):
return 5
elif (Id > 50 and Id <= 60):
return 6
elif (Id > 60 and Id <= 70):
return 7
elif (Id > 70 and Id <= 80):
return 8
elif (Id > 80 and Id <= 90):
return 9
elif (Id > 90 and Id <= 100):
return 10

This is the error

ERROR 000539: Traceback (most recent call last):
File "<expression>", line 1, in <module>
File "<string>", line 2, in Reclass
NameError: name 'Id' is not defined
Failed to execute (CalculateField).

I don't know what Name Id is not defined means as i defined it just like the example.