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()Tier 1 · precalculus
Quadratic Solver
Solves ax^2+bx+c=0 with the quadratic formula.
Files (1)
How to use it
Launch QUAD from the prgm key. The program will prompt you three times:
a:— enter the coefficient in front of x² (the leading term).b:— enter the coefficient in front of x.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.
- Run
QUAD. - At
a:type 1, pressenter. - At
b:type -3, pressenter. - At
c:type 2, pressenter. - 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)
| ID | Inputs | Expected contains |
|---|---|---|
| roots-2-1 | 1, -3, 2 | x1=2.0, x2=1.0 |
| no-real | 1, 0, 1 | no real |