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 ++++------ 04-schleife/blumen.py | 23 +++++++++++ directory-struct/autodir.py | 40 ++++++++++++++++++++ polymonial/polynomial_test.py | 18 +++++---- 4 files changed, 81 insertions(+), 20 deletions(-) diff --git a/04-schleife/blumen.py b/04-schleife/blumen.py new file mode 100644 index 0000000..1641f3c --- /dev/null +++ b/04-schleife/blumen.py @@ -0,0 +1,23 @@ +import turtle + +fenster_breite = 800 +fenster_hoehe = 800 + +screen = turtle.Screen() + +screen.setup(fenster_breite, fenster_hoehe) + +anna = turtle.Turtle() + +b = 100 +h = 100 + +pental = 5 +winkel = 360/pental + +for i in range(0,pental): + anna.circle(b) + anna.left(winkel) + +turtle.done() + diff --git a/directory-struct/autodir.py b/directory-struct/autodir.py new file mode 100644 index 0000000..64a0a14 --- /dev/null +++ b/directory-struct/autodir.py @@ -0,0 +1,40 @@ +tree = { + "document" : { + "protokol" : "template.xlce", + "tech": { + + } + }, + "Zeichnung" : None, + "video": None +} + +from pathlib import Path +import sys + +tree = [ + "document/protokoll/", + "document/tech", + "Zeichnung/", + "video" +] + +def mkdir_struct(tree, prefix="./"): + parent = Path(prefix) + if parent.is_dir(): + for p in tree: + directory = parent.joinpath(p) + directory.mkdir(parents=True, exist_ok=True) + else: + print(f"{prefix} ist kein Ordner oder existiert nicht") + + +prefix = sys.argv[1] +mkdir_struct(tree, prefix) + +tree2 = [ + "photos/urlaub", + "photos/screenshots", + "bluetooth/" +] +mkdir_struct(tree2, "") \ No newline at end of file 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) diff --git a/polymonial/polynomial_test.py b/polymonial/polynomial_test.py index fc49e68..f232260 100644 --- a/polymonial/polynomial_test.py +++ b/polymonial/polynomial_test.py @@ -3,8 +3,9 @@ def test_polynomial_representation(): c = Polynomial(5, 6, 0, -7) - s = f'{c}' - assert s == '5 6 0 -7' + r = repr(c) + s = str(c) + print(r, s, c) def test_evaluate(): l = Polynomial(-12.5, 3.6) @@ -15,14 +16,15 @@ def test_evaluate_2(): l = Polynomial(11, 7, -5, -4, 2) x = 2 - rest_expected = [-3, -5, 0, 2] + q_expected = [-3, -5, 0, 2] y_expected = 5 - (y, rest) = l.evaluate(x) + (y, q) = l.evaluate(x) assert abs(y - y_expected) < EPSILON - for (i, r) in enumerate( rest_expected ): - assert abs(r - rest[i]) < EPSILON - + for (i, r) in enumerate( q_expected ): + assert abs(r - q[i]) < EPSILON + print(Polynomial(*q)) if __name__ == "__main__": - test_evaluate_2() \ No newline at end of file + #test_evaluate_2() + test_polynomial_representation() \ No newline at end of file -- Gitblit v1.10.0-SNAPSHOT