Can't seem to figure out what is wrong with this create fields from a calculation. The code creates the new field in the shapefile as selected by the user but I keep getting a 9999 error on every attempt I have to go further. I am rather new to Python and ArcPy, if anyone has any suggestions they would be greatly appreciated. The code is to work as a tool from an exported route from a network analysis and provide a fuel cost which changes slightly in relation to the speed limit of the road. Thanks.
import arcpy from arcpy import env import os inputFC = arcpy.GetParameterAsText(0) # Input feature class distanceField = arcpy.GetParameterAsText(1) # Name of distance field in input fc speedField = arcpy.GetParameterAsText(2) # Name of speed field in input feature class price = float(arcpy.GetParameterAsText(3)) # Input the current price of gas in $/Liter mpg = float(arcpy.GetParameterAsText(4)) # Input vehicle mpg in MPG arcpy.AddField_management(inputFC, 'Cost', 'DOUBLE') #create cost field rows = arcpy.SearchCursor(inputFC) #row = rows.NextRow() #arcpy.AddMessage(row.GetValue(distanceField)) for row in rows: arcpy.AddMessage(row.length_12) distance = row.getValue(distanceField) arcpy.AddMessage(distance) lperkm = row.getValue(mpg) milageupdate = lperkm * 2.35214 #convert mpg to liters per kilometer if speedField <= 30: cost =(price * 0.07 * distance)/ milageupdate -(milageupdate * (0.07)) elif speedField >30 and speedField <50: cost =(price * distance)/ milageupdate -(milageupdate * (0.03)) elif speedField >50 and speedField <90: cost =(price * distance)/ milageupdate row.setValue('Cost', cost) rows.updateRow(row) del row, rows