# Calculating a percent from attributes in label expression

I am trying to edit my existing python code in the label expression in order to add one more bit of information to the map.

The purpose is to automate fire maps creation through data driven pages for info/billing purposes. The existing code displays the acreage of the owner agencies responsible the fire. It would be ideal if it will display their ownership as a percentage as well.

Attached is an example of the map currently being produced. Code for the label in the center of the fire:

``````def FindLabel ( [BLM] , [BR] , [DNR] , [DOD] , [DOE] , [NPS] , [OS] , [Private] , [SITLA] , [SL_F] , [Tribal] , [UDOT] , [UDWR] , [USFS] , [USFWS] , [USP] ):
xBLM = xBR = xDNR = xDOD = xDOE = xNPS = xOS = xPrivate = xSITLA = xSL_F = xTribal = xUDOT = xUDWR = xUSFS = xUSFWS = xUSP = ""
if [BLM]:
xBLM = "BLM: {} acres \n".format([BLM])
if [BR]:
xBR= "BR: {} acres \n".format([BR])
if [DNR]:
xDNR= "DNR: {} acres \n".format([DNR])
if [DOD]:
xDOD= "DOD: {} acres \n".format([DOD])
if [DOE]:
xDOE= "DOE: {} acres \n".format([DOE])
if [NPS]:
xNPS= "NPS: {} acres \n".format([NPS])
if [OS]:
xOS= "OS: {} acres \n".format([OS])
if [Private]:
xPrivate= "Private: {} acres \n".format([Private])
if [SITLA]:
xSITLA= "SITLA: {} acres \n".format([SITLA])
if [SL_F]:
xSL_F= "SL_F: {} acres \n".format([SL_F])
if [Tribal]:
xTribal= "Tribal: {} acres \n".format([Tribal])
if [UDOT]:
xUDOT= "UDOT: {} acres \n".format([UDOT])
if [UDWR]:
xUDWR= "UDWR: {} acres \n".format([UDWR])
if [USFS]:
xUSFS= "USFS: {} acres \n".format([USFS])
if [USFWS]:
xUSFWS= "USFWS: {} acres \n".format([USFWS])
if [USP]:
xUSP= "USP: {} acres \n".format([USP])

return "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}".format(xBLM, xBR, xDNR, xDOD, xDOE, xNPS, xOS, xPrivate, xSITLA, xSL_F, xTribal, xUDOT, xUDWR, xUSFS, xUSFWS, xUSP)
``````

If you have a field that represents the total area of the fire perimeter, which if you don't you can create it and calculate it in acres. You could then use that field, we will call it `AREA`, in combination with your other fields like this:

``````def FindLabel ( [AREA], [BLM]):
return 'Percentage: %s' % str(float([BLM])/float([AREA]))
``````

``````total = sum(map(int,locals().values())) # collect all passed values, cast to int (or float), and sum