0% found this document useful (0 votes)
4 views2 pages

Factorization Code

The document outlines a Python program for a Factorization App that accepts a quadratic polynomial in the form (ax**2) + bx + c. It prompts the user for coefficients a, b, and c, and provides options to display the polynomial and its factorization, including handling various cases for positive and negative coefficients. The program includes error handling for invalid inputs and allows users to choose whether to include decimal coefficients in the output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Factorization Code

The document outlines a Python program for a Factorization App that accepts a quadratic polynomial in the form (ax**2) + bx + c. It prompts the user for coefficients a, b, and c, and provides options to display the polynomial and its factorization, including handling various cases for positive and negative coefficients. The program includes error handling for invalid inputs and allows users to choose whether to include decimal coefficients in the output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

print("Welcome to the Factorization App.

Please enter a polynomial in the form


(ax**2)+bx+c. Note that this verion of the app only works for QUADRATIC
polynomials")
a=float(input("Enter the coefficient of x**2(a):"))
b=float(input("Enter the coefficient of x(b):"))
c=float(input("Enter the coefficient of x**0(c):"))
d= -(-b+((b**2-4*a*c)**0.5))/2*a
e=-(-b-((b**2-4*a*c)))/2*a
f=int(d)
g=int(e)
k=int(a)
l=int(b)
m=int(c)
h=input("Do you want the coefficients of the variables in your polynomial
including decimals?:")
if h=="YES" or h=="Yes" or h=="yes":
if a>0 and b>0 and c>0 or a<0 and b>0 and c>0:
print(a,"x**2 +",b,"x +",c)
elif a==1 and b>0 and c>0:
print("x**2 +",b,"x +",c)
elif a==1 and b>0 and c<0:
print("x**2 +",b,"x",c)
elif a==1 and b<0 and c>0:
print("x**2",b,"x +",c)
elif a==1 and b<0 and c<0:
print("x**2",b,"x",c)
elif a<0 and b<0 and c<0:
print(a,"x**2",b,"x",c)
elif a>0 and b>0 and c<0 or a<0 and b>0 and c<0:
print(a,"x**2 +",b,"x",c)
elif a>0 and b<0 and c>0:
print(a,"x**2",b,"x +",c)
elif a<0 and b>0 and c>0:
print(a,"x**2 +",b,"x +",c)
elif a<0 and b<0 and c>0:
print(a,"x**2",b,"x +",c)
elif a>0 and b<0 and c<0:
print(a,"x**2",b,"x",c)
elif a==0 and b>0 and c>0 or a==0 and b<0 and c>0:
print(b,"x +",c)
elif b==0 and a>0 and c>0 or b==0 and a<0 and c>0:
print(a,"x**2 +",c)
elif c==0 and b>0 and a>0 or c==0 and a<0 and b>0:
print(a,"x**2 +",b,"x")
elif a==0 and b<0 and c<0 or a==0 and b>0 and c<0:
print(b,"x",c)
elif b==0 and a<0 and c<0 or b==0 and a>0 and c<0:
print(a,"x**2",c)
elif c==0 and b<0 and a<0 and c==0 and b<0 and a>0:
print(a,"x**2",b,"x")
else:
print("Invalid input.")
else:
if k>0 and l>0 and m>0 or k<0 and l>0 and m>0:
print(k,"x**2 +",l,"x +",m)
elif k<0 and l<0 and m<0:
print(a,"x**2",l,"x",m)
elif k==1 and l>0 and m>0:
print("x**2 +",l,"x +",m)
elif k==1 and l>0 and m<0:
print("x**2 +",l,"x -",-m)
elif k==1 and l<0 and m>0:
print("x**2",l,"x +",m)
elif k==1 and l<0 and m<0:
print("x**2",l,"x",m)
elif k>0 and l>0 and m<0 or k<0 and l>0 and m<0:
print(k,"x**2 +",l,"x",m)
elif k>0 and l<0 and m>0:
print(k,"x**2 -",-l,"x +",m)
elif k<0 and l>0 and m>0:
print(k,"x**2 +",l,"x +",m)
elif k<0 and l<0 and m>0:
print(k,"x**2",l,"x +",m)
elif k>0 and l<0 and m<0:
print(k,"x**2 -",-l,"x -",-m)
elif k==0 and l>0 and m>0 or k==0 and l<0 and m>0:
print(l,"x +",m)
elif l==0 and k>0 and m>0 or l==0 and k<0 and m>0:
print(k,"x**2 +",m)
elif m==0 and l>0 and k>0 or m==0 and k<0 and l>0:
print(k,"x**2 +",l,"x")
elif k==0 and l<0 and m<0 or k==0 and l>0 and m<0:
print(l,"x",m)
elif l==0 and k<0 and m<0 or l==0 and k>0 and l<0:
print(k,"x**2",l)
elif m==0 and l<0 and k<0 and m==0 and l<0 and k>0:
print(k,"x**2",l,"x")
else:
print("Invalid input.")
i=input("Do you want the factorization of your polynomial including decimals?:")
if i=="YES" or i=="Yes" or i=="yes":
if d>0 and e<0:
print("(x +",d,")(x",e,")")
elif d<0 and e>0:
print("(x",d,")(x +",e,")")
elif d==0 and e>0:
print("(x)(x +",e,")")
elif d==0 and e<0:
print("(x)(x",e,")")
elif d>0 and e==0:
print("(x +",d,")(x)")
elif d<0 and e==0:
print("(x",d,")(x)")
elif d>0 and e>0:
print("(x +",d,")(x +",e,")")
elif d<0 and e<0:
print("(x",d,")(x",e,")")
else:
print("Invalid input.")
else:
if f>0 and g<0:
print("(x +",f,")(x",g,")")
elif f<0 and g>0:
print("(x",f,")(x +",g,")")
elif f==0 and g>0:
print("(x)(x +",g,")")
elif f==0 and g<0:
print("(x)(x",g,")")
elif f>0 and g==0:
print("(x +",f,")(x)")
elif f<0 and g==0:
print("(x",f,")(x)")
elif f>0 and g>0:
print("(x +",f,")(x +",g,")")
elif f<0 and g<0:
print("(x",f,")(x",g,")")
else:
print("Invalid input.")

You might also like