# buggyConditional.py purpose: Calculate the value of a field based on the values of three input parameters. Create a copy of the data, add the field and set the value.
# Usage: full_path_featureclass_filename Z_value AF_value T_value output_fieldname
# Example input: C:/gispy/data/ch13/tester.gdb/c1 -2 3 6 veld
import arcpy, os
fc = arcpy.GetParameterAsText(0)
Z = arcpy.GetParameterAsText(1)
AF = arcpy.GetParameterAsText(2)
T = arcpy.GetParameterAsText(3)
outFieldName = arcpy.GetParameterAsText(4)
fcCopy = 'C:/gispy/scratch/' + os.path.basename(fc) +'.shp' # Assume this line is ok.
arcpy.CopyFeatures_management(fc, fcCopy ) # Assume this line is ok.

# Add output field to the copy, if it doesn't already exist
fields = arcpy.ListFields(fcCopy)  
fieldNames = [field.name for field in fields]
if field.name in fieldNames:
    arcpy.AddField_management(fcCopy, outFieldName)

if (Z > 0) and (AF > 0):
    value = T + Z + AF    # or = sum([T, Z, AF])
elif (Z > 0) and (AF < 0):
    value = T + Z         # or = sum([T, Z ])
elif (Z < 0) and (AF > 0):
    value = T + AF        # or = sum([T, AF])
else:
    value = T

print("Value: {0}".format(value))

# Set the new field to the output value
results = arcpy.CalculateField_management(fcCopy, outFieldName, T)

print(results.getMessages())