← Library
Tier 1 · precalculus

Quadratic Solver

Solves ax^2+bx+c=0 with the quadratic formula.

Files (1)
QUAD.py227 bytes
def p(s):print(s)
def w():input("...")
def f():
 a=float(input("a:"))
 b=float(input("b:"))
 c=float(input("c:"))
 d=b*b-4*a*c
 if d<0:p("no real")
 else:
  r=d**0.5
  p("x1="+str((-b+r)/(2*a)))
  p("x2="+str((-b-r)/(2*a)))
f()
How to use it

Launch QUAD from the prgm key. The program will prompt you three times:

  1. a: — enter the coefficient in front of x² (the leading term).
  2. b: — enter the coefficient in front of x.
  3. c: — enter the constant term.

Press enter after each value. If the discriminant b²−4ac is negative, you'll see no real — meaning both roots are complex. Otherwise you'll see x1= and x2= with the two real roots.

Example problem

Solve x² − 3x + 2 = 0.

Coefficients are a=1, b=−3, c=2.

  1. Run QUAD.
  2. At a: type 1, press enter.
  3. At b: type -3, press enter.
  4. At c: type 2, press enter.
  5. Output: x1=2.0, x2=1.0.

Verify by factoring: (x−2)(x−1) = 0 → x = 2 or x = 1. ✓

TI-84 Plus CE — try before committingoff
TI-84 Plus CE



  (calculator off)

  Press ON to start.
Test cases (2)
IDInputsExpected contains
roots-2-11, -3, 2x1=2.0, x2=1.0
no-real1, 0, 1no real