Quadratic Formula Solver Error
<p>I'm writing a python quadratic equation solver, and it was working fine, then I ran it another time, and it gave me the following error:</p>

<pre><code>Traceback (most recent call last):
  File "/Users/brinbrody/Desktop/PythonRunnable/QuadraticSolver.py", line 18, in &lt;module&gt;
    rted = math.sqrt(sqb-ac4)
ValueError: math domain error
</code></pre>

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

<pre><code>#Quadratic Formula Solver

#Imports
import math

#User Inputs
a = int(input("a = "))
b = int(input("b = "))
c = int(input("c = "))

#Variables
sqb = b**2
ac4 = 4*a*c
a2 = 2*a
negb = 0-b

#Calculations
rted = math.sqrt(sqb-ac4)
top1 = negb + rted
top2 = negb - rted
low1 = round(top1/a2, 2)
low2 = round(top2/a2, 2)

#Output
print("Possible Values of x:")
print("1.",low1)
print("2. ",low2)
</code></pre>

<p>This error is consistent with every input I've tried. </p>

<p>As xli said, this is due to <code>sqb-ac4</code> returning a negative value, and the python math module can't take the square root of a negative value.</p>

<p>A way to fix this is:</p>

<pre><code>import sys
determin = sqb - ac4
if determin &lt; 0:
    print("Complex roots")
    sys.exit()
else:
    rted = math.sqrt(determin)
</code></pre>

python math.sqrt