Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| lehrkraefte:blc:informatik:glf24:laby:labyrintklasse [2025/05/13 09:03] – created Ivo Blöchliger | lehrkraefte:blc:informatik:glf24:laby:labyrintklasse [2025/06/05 08:31] (current) – [Aufgabe 1] Ivo Blöchliger | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Labyrinth Klasse ====== | ====== Labyrinth Klasse ====== | ||
| + | <WRAP important> | ||
| + | Falls Sie die Dateien '' | ||
| + | </ | ||
| + | * Speichern Sie die Labyrinth-Klasse {{lehrkraefte: | ||
| + | ===== Aufgabe 0 ===== | ||
| + | * Öffnen Sie das Verzeichnis '' | ||
| + | * Legen Sie im Verzeichnis '' | ||
| + | <code python aufgabe0.py> | ||
| + | # Von der Datei laby.py die Klasse Laby importieren: | ||
| + | from laby import Laby | ||
| + | |||
| + | # Ein Labyrinth-Objekt der Grösse 4x3 erzeugen und in der Variablen lab speichern | ||
| + | lab = Laby(4,3) | ||
| + | # lab ausgeben | ||
| + | # dabei wird die Laby-Funktion __str__ aufgerufen, die die Zeichenkette produziert | ||
| + | print(lab) | ||
| + | |||
| + | |||
| + | print(" | ||
| + | lab[1, | ||
| + | # Markierung anbringen | ||
| + | lab[1, | ||
| + | print(lab) | ||
| + | |||
| + | |||
| + | lab[1, | ||
| + | # Markierung anbringen | ||
| + | lab[1, | ||
| + | print(lab) | ||
| + | |||
| + | for richtung in range(4): | ||
| + | print(f" | ||
| + | </ | ||
| + | * Führen Sie das Programm aus. | ||
| + | * Studieren Sie das Programm und verstehen Sie es. | ||
| + | |||
| + | ===== Aufgabe 1 ===== | ||
| + | * Kopieren Sie den Inhalt der Datei '' | ||
| + | * Passen Sie das Programm in der Datei '' | ||
| + | * Entfernen Sie auch allen überflüssigen Code. | ||
| + | <code txt> | ||
| + | +---+---+---+---+---+ | ||
| + | | | ||
| + | +---+---+ | ||
| + | | | ||
| + | +---+---+ | ||
| + | | | | ||
| + | +---+---+ | ||
| + | | | ||
| + | +---+---+ | ||
| + | | | ||
| + | +---+---+---+---+---+ | ||
| + | </ | ||
| + | * Hinweis: Das Programm könnte kompakt mit der Methode '' | ||
| + | * z.B. liefert '' | ||
| + | * z.B. wird mit '' | ||
| + | |||
| + | <hidden Lösungsvorschläge> | ||
| + | <code python> | ||
| + | for xy in range(4): | ||
| + | lab[2, | ||
| + | lab[xy, | ||
| + | </ | ||
| + | |||
| + | <code python> | ||
| + | for richtung in range(4): | ||
| + | lab[2, | ||
| + | lab[2, | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== Aufgabe 2 ===== | ||
| + | * Testen und verstehen Sie das Programm '' | ||
| + | <code python aufgabe2.py> | ||
| + | from laby import Laby | ||
| + | |||
| + | l = Laby(10,5) | ||
| + | for x in range(l.breite-1): | ||
| + | l[x, | ||
| + | |||
| + | print(l) | ||
| + | </ | ||
| + | * Erweitern Sie das Programm so , dass folgendes Labyrinth produziert wird: | ||
| + | <code txt> | ||
| + | +---+---+---+---+---+---+---+---+---+---+ | ||
| + | | | | ||
| + | +---+---+---+---+---+---+---+---+---+---+ | ||
| + | | | | ||
| + | +---+---+---+---+---+---+---+---+---+---+ | ||
| + | | | | ||
| + | +---+---+---+---+---+---+---+---+---+---+ | ||
| + | | | | ||
| + | +---+---+---+---+---+---+---+---+---+---+ | ||
| + | | | | ||
| + | +---+---+---+---+---+---+---+---+---+---+ | ||
| + | </ | ||
| + | <hidden Lösungsvorschlag> | ||
| + | Packen Sie for-Schleife für die $x$-Koordinate in eine weitere for-Schleife für die $y$-Koordinate. | ||
| + | </ | ||