# Lesson goal: Using the Quadratic Formula

Previous: Throwing darts to find Pi | Home | Next: The Pythagorean Theorem Calculator

Remember solving quadractic equations? If you have a quadractic equation in "standard form," which is $Ax^2+Bx+C=0$, then the two solutions to this equation will be $$x=\frac{-B\pm\sqrt{B^2-4AC}}{2A}.$$

In grade-school algebra the equations are kept simple in that the roots (or answers) to quadractic equations are always real. If you look carefully at the quadractic formula, there is a $\sqrt{B^2-4AC}$. As you know, you cannot take the square root of a negative number (if you want roots that are real numbers). In other words, $B^2-4AC$ (which is called the discriminant) must always be $\ge 0$, so in a quadratic equation solver, we must check that this is true (with an if statement) before continuing.

# Now you try. Put some inequality to test in the if statement. You also have to complete the x1= and x2= lines to give the $+$ and $-$ roots, as computed with the quadratic formula above.

Type your code here:

See your results here:

This code will not run! What will you put in the if ???? then statement to ensure that $d$ (the discriminant) is $\ge 0$ before continuing to compute $x1$ and $x2$, the two solutions to the equation?

By the way, in this case we'll say that $x1=\frac{-B+\sqrt{B^2-4AC}}{2A}$ and $x2=\frac{-B-\sqrt{B^2-4AC}}{2A}.$ Dismiss.

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

3. Then click the "Use on iPhone" button that you'll see.