Quadractic Formula mix up
<p>So I made a python code that solves for x using the quadratic formula. Everything works out in the end except for the signs. For instance, if you want to factor x^2 + 10x + 25, my code outputs -5, -5 when the answer should be 5, 5.</p>

<pre><code>def quadratic_formula():
    a = int(input("a = "))
    b = int(input("b = "))
    c = int(input("c = "))
    bsq = b * b
    fourac = 4 * a * c
    sqrt = (bsq - fourac) ** (.5)
    oppb = -b
    numerator_add = (oppb) + (sqrt)
    numerator_sub = (oppb) - (sqrt)
    twoa = 2 * a
    addition_answer = (numerator_add) / (twoa)
    subtraction_answer = (numerator_sub) / (twoa)
    print(addition_answer)
    print(subtraction_answer)
</code></pre>

<p>Your solution is fine, let's prove it using <a href="http://www.sympy.org/en/index.html" rel="nofollow">sympy</a>:</p>

<pre><code>&gt;&gt;&gt; (x**2+10*x+25).subs(x,-5)
0
</code></pre>

<p>As you can see, -5 is one of the roots while 5</p>

<pre><code>&gt;&gt;&gt; (x**2+10*x+25).subs(x,5)
100
</code></pre>

<p>is not, now... if you expand your 2 roots [-5,-5] like:</p>

<pre><code>&gt;&gt;&gt; ((x+5)*(x+5)).expand()
x**2 + 10*x + 25
</code></pre>

<p>You can see like the result matches.</p>

<p>In fact, you can also confirm the roots are correct displaying the quadratic equation:</p>

<p><a href="http://i.stack.imgur.com/GXyQ1.png" rel="nofollow"><img src="http://i.stack.imgur.com/GXyQ1.png" alt="enter image description here"></a></p>

<p>I'd strongly recommend you review the concept of <a href="http://www.sosmath.com/algebra/factor/fac08/fac08.html" rel="nofollow">The Quadratic Formula</a> and when it's clear just come back to the coding</p>

python math quadratic