I am trying to make a program where it takes a trinomial and factors it, if possible. Whenever the user inputs A, B, and C, the trinomial is supposed to be taken through the factor(product, summation) function, but I can’t seem to figure out how to assign A and C to the product arg and B to the summation.
import math
import cmath
def factor(product, summation):
for i in range(-abs(product), abs(product) + 1):
if i == 0:
continue
if product % i == 0: # Ensure i is a factor of the product
j = product // i # Find the corresponding factor
if i + j == summation: # Check if the sum of the factors matches the given summation
return i, j
return None
#Assign the coefficients
print('Follow this format: Ax^2 + Bx + C')
a = float(input('Enter A: '))
b = float(input('Enter B: '))
c = float(input('Enter C: '))
#Give a space between everything
print(' ')
print (f'{a}x^2 + {b}x + {c}')
factor(product, summation)
I tried declaring different variables outside the function, product = (a*c) and summation = b, but it doesn’t make sense and I am overall lost on how to tie all of this together.