Obrigado pela resposta. eu dei uma ajeitada no codigo ele roda mas fica com alguns erros ainda: def l_bissecao(f, a, b, epsilon, maxIter=50):     fa=f(a)     fb=f(b)     if fa*fb > 0:         print("Erro! A funçao não muda de sinal.")         return (True, None)     print("k\t  a\t\t  fa\t\t  b\t\t  fb\t\t  x\t\t  fx\t\tintervX")     intervX = abs(b-a)     x = (a+b)/2     fx = f(x)     print("-\t%e\t%e\t%e\t%e\t%e\t%e\t%e"%(a, fa, b, fb, x, fx, intervX))     if intervX <= epsilon:         k = 1     while k <= maxIter:         if fa * fx > 0:             a = x             fa = fx         else:             b = x             fb = fx         intervX = abs(b-a)         x = (a+b)/2         fx = f(x)         print("%d\t%e\t%e\t%e\t%e\t%e\t%e\t%e"%(k,a, fa, b, fb, x, fx, intervX))         if intervX <= epsilon:             return(False, None)         k = k+1     print("O numero maximo de iteracoes foi atingido.")     return (True, x)  if __name__ == "__main__":          def f1(x):         return x**3-9*x+3     a = 0     b = 1     epsilon = 10**-8     maxIter = 20     print("Método da Bisseção")     (houveErro, raiz) = l_bissecao(f1,a,b,epsilon,maxIter)     if houveErro:         print("O Método da Bisseção retornou um erro.")     if raiz is not None:         print("Raiz encontrada: %s"%raiz) diz que os erros são na linha 56 e 24 File "teste.py", line 56, in <module>     (houveErro, raiz) = l_bissecao(f1,a,b,epsilon,maxIter)   File "teste.py", line 24, in l_bissecao     while k <= maxIter: UnboundLocalError: local variable 'k' referenced before assignment