← Library
Tier 1 · precalculus

Poly Eval

Evaluate polynomial via Horner's method.

Files (1)
POLYEVAL.py325 bytes
def p(s):print(s)
def o1():
 p("=POLY EVAL=")
 n=int(input("deg:"))
 c=[]
 for i in range(n+1):
  c.append(float(input("c:")))
 x=float(input("x:"))
 r=0.0
 for k in c:r=r*x+k
 p("p(x)="+str(r))
def menu():
 while True:
  p("=POLYEVAL=")
  p("1:EVAL")
  p("0:EXIT")
  c=input("?>")
  if c=="1":o1()
  elif c=="0":break
menu()
How to use it

Evaluates a polynomial at a given x using Horner's method (fast, no **).

Launch POLYEVAL from prgm, choose 1:EVAL, then:

  1. deg: — degree of the polynomial (e.g. 2 for a quadratic).
  2. c: — the leading coefficient, then each lower-degree coefficient in order, highest first, including zeros.
  3. x: — the value to evaluate at.

Output is p(x)=. Enter exactly deg+1 coefficients.

Example problem

Evaluate p(x) = 2x + 5 at x = 3.

Degree 1, coefficients [2, 5] (highest-first).

  1. Run POLYEVAL, choose 1:EVAL.
  2. deg:1.
  3. c:2, c:5.
  4. x:3.
  5. Output: p(x)=11.0.

Verify: 2(3) + 5 = 11. ✓

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



  (calculator off)

  Press ON to start.
Test cases (2)
IDInputsExpected contains
cubic-x21, 3, 1, 2, 3, 4, 2, 0p(x)=
linear-x31, 1, 2, 5, 3, 0p(x)=11.0