From d212cd913e7c808f57dd862300f7b19e11cab3a4 Mon Sep 17 00:00:00 2001 From: Hong-Phuc Bui <hong-phuc.bui@htwsaar.de> Date: Mon, 15 Jul 2024 12:26:11 +0200 Subject: [PATCH] turtle vererbung --- datei-idiome/tests/wettercdc/WetterStation_tests.py | 19 ++++ .gitignore | 5 turtle-geo-inheritance/src/turtlegeo/TtGeo.py | 11 ++ study-effort/.gitignore | 3 study-effort/src/mystudy/main.py | 2 turtle-geo-inheritance/.gitignore | 3 datei-idiome/file-lesen.py | 8 ++ /dev/null | 28 ------- study-effort/src/mystudy/lecture.py | 5 turtle-geo-inheritance/src/turtlegeo/main.py | 5 datei-idiome/tests/wettercdc/__init__.py | 0 datei-idiome/src/wettercdc/__init__.py | 0 oop/imutable-object/money.py | 25 ++++++ oop/imutable-object/money_test.py | 15 +++ datei-idiome/tests/__init__.py | 0 datei-idiome/src/wettercdc/search_station.py | 19 ++++ datei-idiome/pyproject.toml | 15 +++ datei-idiome/src/wettercdc/WetterStation.py | 23 +++++ study-effort/src/mystudy/LecruresConverter.py | 7 + 19 files changed, 156 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 17c2bab..f839ed4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ sandbox* queens* *.venv* - - - |test| \ No newline at end of file +__pycache__/ +.idea/ diff --git a/datei-idiome/file-lesen.py b/datei-idiome/file-lesen.py new file mode 100644 index 0000000..3cb1638 --- /dev/null +++ b/datei-idiome/file-lesen.py @@ -0,0 +1,8 @@ +import sys + +filename = sys.argv[1] + +with open(filename, 'r') as f: + for line in f.readlines(): + print(line.strip()) + pass \ No newline at end of file diff --git a/datei-idiome/pyproject.toml b/datei-idiome/pyproject.toml new file mode 100644 index 0000000..762bbb6 --- /dev/null +++ b/datei-idiome/pyproject.toml @@ -0,0 +1,15 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "wettercdc" +version = "0.0.1" + +[tool.setuptools.packages.find] +# All the following settings are optional: +where = ["src"] + +# [project.scripts] +# mystudy = "mystudy.main:start" + diff --git a/datei-idiome/src/wettercdc/WetterStation.py b/datei-idiome/src/wettercdc/WetterStation.py new file mode 100644 index 0000000..2cffd02 --- /dev/null +++ b/datei-idiome/src/wettercdc/WetterStation.py @@ -0,0 +1,23 @@ +import re + +class WetterStation: + """ + represents a Weather station + """ + def __init__(self, station_line: str): + fields = re.split(r"\s+", station_line.strip()) + self._id = fields[0] + self._bundesland = fields[-1] + self._name = fields[-2] + + def id(self): + return self._id + + def name(self): + return self._name + + def bundesland(self): + return self._bundesland + + pass + diff --git a/datei-idiome/src/wettercdc/__init__.py b/datei-idiome/src/wettercdc/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/datei-idiome/src/wettercdc/__init__.py diff --git a/datei-idiome/src/wettercdc/search_station.py b/datei-idiome/src/wettercdc/search_station.py new file mode 100644 index 0000000..c8ad675 --- /dev/null +++ b/datei-idiome/src/wettercdc/search_station.py @@ -0,0 +1,19 @@ +# suche aus Beschreibung die Station aus gewünsche Bundesland +import sys + +from wettercdc.WetterStation import WetterStation + +filename = sys.argv[1] +stations = [] + +with open(filename, 'r') as f: + ignore_lines = 2 + for i in range(ignore_lines): + f.readline() + + for line in f.readlines(): + #TODO: mach was mit line + stations.append( WetterStation(line) ) + pass + +print('DONE', len(stations)) diff --git a/datei-idiome/tests/__init__.py b/datei-idiome/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/datei-idiome/tests/__init__.py diff --git a/datei-idiome/tests/wettercdc/WetterStation_tests.py b/datei-idiome/tests/wettercdc/WetterStation_tests.py new file mode 100644 index 0000000..9158c9c --- /dev/null +++ b/datei-idiome/tests/wettercdc/WetterStation_tests.py @@ -0,0 +1,19 @@ +import unittest +from typing import Final + +from wettercdc.WetterStation import WetterStation + + +class WetterStationCase(unittest.TestCase): + def test_constructor(self): + line:Final[str] = """00020 20040812 20240701 432 48.9219 9.9129 Abtsgmünd-Untergröningen Baden-Württemberg +""" + station = WetterStation(line) + self.assertEqual(station.id(), '00020') + self.assertEqual(station.name(), "Abtsgmünd-Untergröningen") + self.assertEqual(station.bundesland(), "Baden-Württemberg") + + + +if __name__ == '__main__': + unittest.main() diff --git a/datei-idiome/tests/wettercdc/__init__.py b/datei-idiome/tests/wettercdc/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/datei-idiome/tests/wettercdc/__init__.py diff --git a/oop/imutable-object/money.py b/oop/imutable-object/money.py new file mode 100644 index 0000000..0b6be40 --- /dev/null +++ b/oop/imutable-object/money.py @@ -0,0 +1,25 @@ +class Money: + def __init__(self, euro: int, cent: int = 0 ): + if euro < 0: + raise ValueError("Betrag ungültig") + if euro == 0 and cent == 0: + raise ValueError("Betrag ungültig") + if cent < 0: + raise ValueError("Betrag ungültig") + + self._betrag = euro * 100 + cent # in cent + self._euro, self._cent = divmod(self._betrag, 100) + pass + + + def normalize(self) -> str: + return f"{self._euro}€{self._cent}c" + + def __repr__(self): + return self.normalize() + + def getEuro(self): + return self._euro + + def add(self, euro): + return Money(self._euro + euro, self._cent) \ No newline at end of file diff --git a/oop/imutable-object/money_test.py b/oop/imutable-object/money_test.py new file mode 100644 index 0000000..b20c2d7 --- /dev/null +++ b/oop/imutable-object/money_test.py @@ -0,0 +1,15 @@ +import unittest + + +class MyTestCase(unittest.TestCase): + def test_something(self): + benzin_preis = Money(12, 5) + + milch_preis = Money(3) + katoffel_p = Money(0, 501) + pass + + + +if __name__ == '__main__': + unittest.main() diff --git a/study-effort/.gitignore b/study-effort/.gitignore new file mode 100644 index 0000000..b0837d2 --- /dev/null +++ b/study-effort/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +*.egg-info/ +.idea/ \ No newline at end of file diff --git a/study-effort/dem-vorlesung.html b/study-effort/dem-vorlesung.html deleted file mode 100644 index e6454e9..0000000 --- a/study-effort/dem-vorlesung.html +++ /dev/null @@ -1,28 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <title>Vorlesung</title> -</head> -<body> - -<table> - <tr> - <td>Mathematik</td> - <td>2.5</td> - <td>5</td> - </tr> - <tr> - <td>Prog 2</td> - <td>2.0</td> - <td>5</td> - </tr> - <tr> - <td>Informatik 2</td> - <td>2.0</td> - <td>5</td> - </tr> -</table> - -</body> -</html> \ No newline at end of file diff --git a/study-effort/src/mystudy/LecruresConverter.py b/study-effort/src/mystudy/LecruresConverter.py new file mode 100644 index 0000000..d484890 --- /dev/null +++ b/study-effort/src/mystudy/LecruresConverter.py @@ -0,0 +1,7 @@ +from mystudy.lecture import Lecture + + +class LecturesConvert: + def covert(self, lectures: list[Lecture]) -> str: + pass + diff --git a/study-effort/src/mystudy/lecture.py b/study-effort/src/mystudy/lecture.py index 64de7ca..5856cfc 100644 --- a/study-effort/src/mystudy/lecture.py +++ b/study-effort/src/mystudy/lecture.py @@ -1,6 +1,7 @@ from typing import Final from mystudy.DataFormatError import DataFormatError +from mystudy.LecruresConverter import LecturesConvert lecture_time: Final[int] = 15 ects_effort: Final[int] = 30 @@ -56,7 +57,7 @@ pass -class Lecture2HTMLConverter: +class Lecture2HTMLConverter(LecturesConvert): def __init__(self): self.__head = """<!DOCTYPE html> <html lang="en"> @@ -70,7 +71,7 @@ </html> """ - def to_html(self, lectures: list[Lecture]) -> str: + def convert(self, lectures: list[Lecture]) -> str: html = "" for l in lectures: html += f"""<tr> diff --git a/study-effort/src/mystudy/main.py b/study-effort/src/mystudy/main.py index 2110e83..9195a37 100644 --- a/study-effort/src/mystudy/main.py +++ b/study-effort/src/mystudy/main.py @@ -23,7 +23,7 @@ lectures = read_file_to_lecture(filename) if lectures is not None: converter = Lecture2HTMLConverter() - html_code = converter.to_html(lectures) + html_code = converter.convert(lectures) print(html_code) except FileNotFoundError: print(f"Datei '{filename}' nicht gefunden") diff --git a/turtle-geo-inheritance/.gitignore b/turtle-geo-inheritance/.gitignore new file mode 100644 index 0000000..b0837d2 --- /dev/null +++ b/turtle-geo-inheritance/.gitignore @@ -0,0 +1,3 @@ +__pycache__ +*.egg-info/ +.idea/ \ No newline at end of file diff --git a/turtle-geo-inheritance/src/turtlegeo/TtGeo.py b/turtle-geo-inheritance/src/turtlegeo/TtGeo.py index 5a248c0..6e63476 100644 --- a/turtle-geo-inheritance/src/turtlegeo/TtGeo.py +++ b/turtle-geo-inheritance/src/turtlegeo/TtGeo.py @@ -15,4 +15,13 @@ self.setheading(head) pass - pass \ No newline at end of file + def pentagon(self, length, x, y): + alpha = 72 + self.teleport(x, y) + head = self.heading() + for i in range(0, 5): + self.forward(length) + self.left(alpha) + self.setheading(head) + pass + diff --git a/turtle-geo-inheritance/src/turtlegeo/main.py b/turtle-geo-inheritance/src/turtlegeo/main.py index 31ac99f..b58a3ed 100644 --- a/turtle-geo-inheritance/src/turtlegeo/main.py +++ b/turtle-geo-inheritance/src/turtlegeo/main.py @@ -7,6 +7,7 @@ def main(): t = TtGeo() t.triangle(50, 20, 25) - t.circle(50) - t.dot(25) + t.pentagon(60, 20, 25) + + t.screen.mainloop() -- Gitblit v1.10.0-SNAPSHOT