A Polynomial Class

medium
Unit 13 · Decorators & Classes0/3 to milestone

Implement Poly(coeffs) where coeffs[i] is the coefficient of xix^i (trailing zeros are trimmed; the zero polynomial has coeffs == [0]):

  • degree property (-1... no: the zero polynomial has degree 0 for simplicity)
  • p(x) evaluates with Horner's method
  • +, -, * between polynomials (and with plain numbers on either side)
  • derivative()
  • str(p) like "3x^2 - x + 2": highest power first, coefficient 1 omitted, x instead of x^1, and signs written as + / -
Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
A Polynomial Class · TechGradify