Hong-Phuc Bui
4 days ago 4c5ba07d9c2f044c179d3bfdd41a6f9f20691ac9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Polynomial:
    def __init__(self, *argv: float):
        self.__coefficients = tuple(argv)
 
 
    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:]
 
    def __repr__(self) -> str:
        coe = []
        for c in self.__coefficients:
            coe.append(f'{c}')
        return ' '.join(coe)