Math Domain Error Quadratic Formula
<p>Figured out the errors except for this last one, Im now getting this error message, and can't figure out why, I'm using the exact formulas for x1 and x2 that my teacher gave us to use and i'm not able to figure the error out.</p>

<pre><code>    # Quadratic Formula

# Import the math library to use sqrt() function to find the square root
import math

print("This equation solves for x in the binomial equation: ax^2 + bx + c = 0")

# Get the equation's coefficients and constant from the user
a = 0
while a == 0:
    try:
        a = float(input("Enter the first coefficeint, or a, value:  "))
        if a == 0:
           raise ValueError
    except ValueError:
        print("The value you entered is invalid. Zero is not allowed")
    else:
            break
while (True):
    try:
        b = float(input("Enter the Second coefficeint, or b, value:  "))
    except ValueError:
            print("The value you entered is invalid. only real numbers")
    else:
            break
while (True):
    try:
        c = float(input("Enter the last coefficeint, or c, value:  "))
    except ValueError:
            print("The value you entered is invalid. only real numbers")
    else:
            break
d = (b**2) - (4*a*c)
x1 = ((-b) + math.sqrt(b**2 - 4*a*c)) / (2*a) 
x2 = ((-b) - math.sqrt(b**2 - 4*a*c)) / (2*a)
print("X is: ", x1, " or ", x2)
do_calculation = True
while(do_calculation):
         another_calculation = input("Do you want to perform another calculation? (y/n):")
if(another_calculation !="y"):
</code></pre>

<p>This equation solves for x in the binomial equation: ax^2 + bx + c = 0
Enter the first coefficeint, or a, value:  2
Enter the Second coefficeint, or b, value:  3
Enter the last coefficeint, or c, value:  4
Traceback (most recent call last):
  File "/Users/cadenhastie/Downloads/Jtwyp6QuadraticEqnCalc/improvedquadraticeqncalc.py", line 34, in 
    x1 = ((-b) + math.sqrt(b**2 - 4*a*c)) / (2*a)
ValueError: math domain error</p>

<p>You have <code>try</code> statements with no corresponding <code>except</code> statement.  You should generally avoid <code>while True:</code>.  The indentation in your code has many issues</p>

<p>To get one value from the user with error handling, you could do something like the code below.  You would then repeat this for each coefficient you want the user to enter.  You probably want to wrap this in a function at some point so you are not writing duplicate code.</p>

<p><code>a = 0
while a == 0:
    try:
        a = float(input("Enter the first coefficeint, or a, value:  "))
        if a == 0:
           raise ValueError
    except ValueError:
        print("The value you entered is invalid. Zero is not allowed")
</code></p>

python quadratic