Hong-Phuc Bui
6 days ago c97d23edee3e224f1bcba0add74b61934ad69ff7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Polynomial:
    def __init__(self, *argv: float):
        self.__coefficients = []
        for c in argv:
            self.__coefficients.append(c)
 
    def __repr__(self) -> str:
        coe = []
        for c in self.__coefficients:
            coe.append(f'{c}')
        return ' '.join(coe)
 
    def __str__(self):
        return self.__repr__()
 
    def  evaluate(self, x: float) -> tuple[float, list[float]]:
        p = self.__coefficients[-1]
        c = [p]
        for ak in self.__coefficients[-2::-1]:
            p = ak + (p * x)
            c.insert(0, p)
        return c[0], c[1:]