What is wrong with the following quadratic equation code?
<p>I am trying to make a program that converts standard form quadratic equations to factored form using the quadratic formula, but I'm getting an error on the part where I begin to do math. It seems like it has a problem with the floats I am using, but I do not know why, nor do I know how to fix it.</p>

<p>This is the error I get:</p>

<pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
  File "C:\Users\Josef\Documents\Python\standardFactored.py", line 25, in &lt;module&gt;
    rightS = b^2-4*a*c
TypeError: unsupported operand type(s) for ^: 'float' and 'float'
</code></pre>

<hr>

<p>Here's the code:</p>

<pre><code>print("This program will convert standard form quadratic equations to "
      "factored form. ax^2+bx+c --&gt; a(x+ )(x+ )")

while True:
    try:
        a = float(raw_input("a = "))
        break
    except:
        print("that is not a valid number")

while True:
    try:
        b = float(raw_input("b = "))
        break
    except:
        print("that is not a valid number")

while True:
    try:
        c = float(raw_input("c = "))
        break
    except:
        print("that is not a valid number")

rightS = b^2-4*a*c
try:
    math.sqrt(rightS)
except:
    ("There is no factored for for this equation")
    quit()
</code></pre>

<p>The <code>^</code> operator probably doesn't do what you expect. It's a binary XOR, or e<strong>X</strong>clusive <strong>OR</strong> operator. The XOR operator doesn't work with floating point numbers, thus producing the error. The error basically says it can't do the operation on two floats. With exponents, use a double asterisk. See the Python operators <a href="https://www.tutorialspoint.com//python/python_basic_operators.htm" rel="nofollow">here</a>.</p>

<p>Example, a to the power b is:</p>

<pre><code>a ** b
</code></pre>

<p>In your case, it would be:</p>

<pre><code>rightS = b ** 2 - 4 * a * c
</code></pre>

python variables math floating-point quadratic