[Tutor] local var error

Prasad microteacher at gmail.com
Mon Mar 15 11:30:24 CET 2010


I am writing a function to find correct transformer lamination for
specific wattage. It gives an error message:

UnboundLocalError: local variable 'stdArea' referenced before assignment




def power2lam():
        voltAmp=raw_input("How much power in Watts you want to handle?:
")
#following dictionary is for finding the correct lamination size
practically available.

dictLam={0.2:32,2:17,5:12,6:1,7:74,10:2,18:45,31:15,45:33,75:13,156:5,494:43}
        temp=dictLam.keys()
        temp.sort()
        vamaxList=temp
        print vamaxList
        for x in vamaxList:
            if x<voltAmp:
                pass#print ".",
            else:
                stdArea=(math.sqrt(x))/6
                print x
                break       #break is needed to prevent further checks
in the dict
        windArea=(math.sqrt(stdArea))*0.75
        windHeight=windArea*2*25.4      #window height in mm
        usefulWindow=windArea*0.6               
        idxLam=vamaxList.index(x)
        idxEcoLam=idxLam-1
        vamax=vamaxList[idxLam]
        slctLam=dictLam[vamax]          #Lamination selected
        print "You need lamination number " +str(slctLam)+ " for your
work."


I am creating a variable in the for loop. Shouldn't it work outside it?
If not, suggest me some remedy.
Thanks in advance.

--prasad mehendale




More information about the Tutor mailing list