{"slug":"poly-eval","tier":1,"subject":"precalculus","title":"Poly Eval","description":"Evaluate polynomial via Horner's method.","files":[{"filename":"POLYEVAL.py","content":"def p(s):print(s)\ndef o1():\n p(\"=POLY EVAL=\")\n n=int(input(\"deg:\"))\n c=[]\n for i in range(n+1):\n  c.append(float(input(\"c:\")))\n x=float(input(\"x:\"))\n r=0.0\n for k in c:r=r*x+k\n p(\"p(x)=\"+str(r))\ndef menu():\n while True:\n  p(\"=POLYEVAL=\")\n  p(\"1:EVAL\")\n  p(\"0:EXIT\")\n  c=input(\"?>\")\n  if c==\"1\":o1()\n  elif c==\"0\":break\nmenu()"}],"testCases":[{"id":"cubic-x2","inputs":["1","3","1","2","3","4","2","0"],"expectedContains":["p(x)="]},{"id":"linear-x3","inputs":["1","1","2","5","3","0"],"expectedContains":["p(x)=11.0"]}],"usage":"Evaluates a polynomial at a given `x` using Horner's method (fast, no `**`).\n\nLaunch `POLYEVAL` from `prgm`, choose `1:EVAL`, then:\n\n1. `deg:` — degree of the polynomial (e.g. 2 for a quadratic).\n2. `c:` — the leading coefficient, then each lower-degree coefficient **in order, highest first**, including zeros.\n3. `x:` — the value to evaluate at.\n\nOutput is `p(x)=`. Enter exactly `deg+1` coefficients.","example":{"problem":"Evaluate `p(x) = 2x + 5` at `x = 3`.","walkthrough":"Degree 1, coefficients [2, 5] (highest-first).\n\n1. Run `POLYEVAL`, choose `1:EVAL`.\n2. `deg:` → **1**.\n3. `c:` → **2**, `c:` → **5**.\n4. `x:` → **3**.\n5. Output: `p(x)=11.0`.\n\nVerify: 2(3) + 5 = 11. ✓"}}