Advanced OOP and patterns · 12 / 15 Exercise Medium

A polynomial called like a function

Objective

With __call__ an object can be called as if it were a function, and at the same time store data. It is useful for functions with configuration (a polynomial, a multiplier, a filter…).

Instructions

  • Create the class Polynomial that receives the list of coefficients (from the highest degree to the lowest) and, when called with x, returns the value of the polynomial.
  • The first line has the coefficients; the second, the number n of values; then n lines with an integer x. Show p(x) = value.
Input
1 2 3
3
0
1
2
Output
p(0) = 3
p(1) = 6
p(2) = 11

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise