Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

local variable 'Integer' referenced before assignment

I'll be honest I have no idea why this error is popping up, and it's really weird! I'm writing code that will generate a closed form solution to the partial sums of integer powers up to n, and this is what I have

def sum_first_n_p_powers(p):
    length = p+1
    vector = zero_vector(length)
    matrix_list = []
    for x in xrange(0,length):
        copy = vector[:]
        for y in xrange(0,length): 
            copy[y] = binomial(length-y,x-y+1)
    M = Matrix(matrix_list)
    solution_vector = zero_vector(length)
    solution_vector[0] = 1
    coeffs = M.solve_right(solution_vector)
    n = var('n')
    0 = polynomial
    for x in xrange(0,len(coeffs)):
        polynomial = polynomial + coeffs[x]*n^(length-x)
    return polynomial

And when I try to run it I get the most unusual error, it just says to me

UnboundLocalError: local variable 'Integer' referenced before assignment. I have never run into this before and have no idea what's wrong with the line. Thanks in advance!