我正在创建一个程序来分解三项式,但我有点困惑和混淆,我不知道如何正确打印输出。
三项式示例:
2x**2+6x+4 = (1x+2)(2x+2)
到目前为止,我的代码只考虑了等式的每个部分
def factortri(x, b, c, e):
for i in range(x):
if i > 0:
if x%i == 0:
if i > x/i:
pass
else:
h = "%s, %s"%(i,x/i)
print h
for i in range(e):
if i > 0:
if e%i == 0:
if i > e/i:
pass
else:
s = (e/i)
f = "%s,%s"%(i,s)
print f
if i*x + s*x == c:
print i
print x
print s
print x
for l in range(b):
if l > 0:
if b%l == 0:
if l > b/l:
pass
else:
r = (b/l)
g = "%s, %s"%(l,r)
if (l+i)*(r+s)== c+e:
print "yes"
if (r+i)*(l+s)== c+e:
print "yes"
if (r+s)*(l+i)== c+e:
print "yes"
if (l+s)*(r+i)== c+e:
print "yes"
x = input("First Tri Co-ef: ")
b = input("First Tri Exponent: ")
c = input("Middle Tri Co-ef: ")
e = input("Last Trinomial: ")
factortri(x, b, c, e)
有没有更简单的方法来做到这一点?