From 4c5ba07d9c2f044c179d3bfdd41a6f9f20691ac9 Mon Sep 17 00:00:00 2001 From: Hong-Phuc Bui <hong-phuc.bui@htwsaar.de> Date: Wed, 04 Jun 2025 14:16:25 +0200 Subject: [PATCH] implement polynomial --- polymonial/polynomial.py | 20 ++++++++------------ 1 files changed, 8 insertions(+), 12 deletions(-) diff --git a/polymonial/polynomial.py b/polymonial/polynomial.py index 0f8052e..b847224 100644 --- a/polymonial/polynomial.py +++ b/polymonial/polynomial.py @@ -1,17 +1,7 @@ class Polynomial: def __init__(self, *argv: float): - self.__coefficients = [] - for c in argv: - self.__coefficients.append(c) + self.__coefficients = tuple(argv) - 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] @@ -19,4 +9,10 @@ for ak in self.__coefficients[-2::-1]: p = ak + (p * x) c.insert(0, p) - return c[0], c[1:] \ No newline at end of file + return c[0], c[1:] + + def __repr__(self) -> str: + coe = [] + for c in self.__coefficients: + coe.append(f'{c}') + return ' '.join(coe) -- Gitblit v1.10.0-SNAPSHOT