I wrote a Python program that does a synthetic division of a polynomial. The polynomial is subject to some limitations (which are listed in the module documentation of the program), mainly because I did not have the time to work out all the edge cases. I would like feedback on anything that is possible, as I would like to solve other polynomials. All feedback is welcome, appreciated and considered!

**synthetic_division.py**

```
"""
SYNTHETIC DIVISION CALCULATOR
This program accepts a polynomial and returns all the
x intercepts.
Program has some constraints:
- Coefficients must only be one digit, if present
- Constant must be one digit, and must be present (even 0)
- Constant must be positive
EX:
Input: x^3 -4x^2 +x +6
Output: X = (3, -1, 2)
"""
from functools import reduce
def get_coefficients(equation):
"""
Returns the coefficients of the passed polynomial. If no coefficent, then 1 is returned.
Only works for single digit coefficents, if present.
:param equation: The equation to be analyzed
"""
parts = equation.split()
coeffs = ()
for part in parts:
if part(0) == "x":
coeffs.append(1)
if part(0) == "-":
coeffs.append(int(part(1)) * -1)
if part(0) == "+" and "x" in part:
if len(part) == 2:
coeffs.append(1)
else:
coeffs.append(int(part(1)))
return coeffs
def get_factors(equation):
"""
Returns a list of factors of the constant
:num n: Number to get factors from
"""
constant = int(equation(len(equation) - 1))
###########################################
"""
===========================================
Equation from StackOverflow user @agf
https://stackoverflow.com/a/6800214/8968906
===========================================
"""
factors = list(
set(
reduce(
list.__add__, (
(i, constant//i) for i in range(1, int(constant**0.5) + 1) if constant % i == 0
)
)
)
)
###########################################
#Add negatives
length = len(factors)
for i in range(length):
factors.append(-factors(i))
return factors
def synthetic_division(coefficients, factors):
"""
Performs synthetic division with the passed coefficients and factors
Returns a list of intercepts
"""
coeffs = coefficients
facs = factors
ints = ()
for fac in facs:
current_sum = 0
for coeff in coeffs:
current_sum += coeff
current_sum *= fac
if current_sum == 0:
ints.append(fac)
return ints
def main(equation):
"""
Gathers the coefficients, factors and intercepts from the equation
:param equation: The polynomial to be solved
"""
coefficients = get_coefficients(equation)
constant = int(equation(len(equation) - 1))
coefficients.append(constant)
factors = get_factors(equation)
intercepts = synthetic_division(coefficients, factors)
return intercepts
if __name__ == '__main__':
EQUATION = "x^3 -4x^2 +1x +6"
print(f"X = {main(EQUATION)}")
```