Okay, I will help you out.
First off, have you heard of the rational root theorem? If you have just use that if not here is an explanation.
Given an arbitrary polynomial, the possible roots of that polynomial are +/- p/q where p is an integer factor of the constant term and q is a factor of the leading term.
Here is how the code would look:
from math import ceil
listOfFactors = lambda n: {i for i in range(1,ceil(abs(n)/2)+1) if n%i == 0}
multiply = lambda a,b: a*b
def polyRoots(polyListCoeff):
allFactors = set()
allFactorsList = list(allFactors.union(listOfFactors(polyListCoeff[0]),{polyListCoeff[0]},listOfFactors(polyListCoeff[-1]),{polyListCoeff[-1]}))
allFactorsList.extend([-1*i for i in allFactorsList])
polyListCoeff.reverse()
return [i for i in allFactorsList if sum([pow(i,j)*polyListCoeff[j] for j in range(0,len(polyListCoeff))]) == 0]
Here is an example for x^2 + 0x -4:
>>> polyRoots([1,0,-4])
[2, -2]
The parameters for polyRoots is a list of the coefficients starting from the leading one.
Now take the roots that you found from polyRoots and make a nice display for the factoring. The factored form the example is (x-2)(x+2)
Thanks