lehrkraefte:blc:informatik:glf24:laby:labyrintklasse

This is an old revision of the document!


Labyrinth Klasse

  • Speichern Sie die Labyrinth-Klasse laby.py im Verzeichnis labyrinth, wo sich bereits die Datei pnmbild.py, etc. befinden.
  • Öffnen Sie das Verzeichnis labyrinth mit VS-Code (File → Open Folder).
  • Legen Sie im Verzeichnis labyrinth eine neue Datei aufgabe1.py an und kopieren Sie folgendes Python-Programm:
aufgab1.py
from laby import Laby
 
l = Laby(4,3)
print(l)
for dir in range(4):
    l[1,1].zustand(dir, True)
print("Jetzt offen:")
print(l)
  • Führen Sie das Programm aus.
  • Studieren Sie das Programm und verstehen Sie es.
  • Passen Sie das Programm so an, dass folgende Ausgabe entsteht:
+---+---+---+---+---+
|   |   |   |   |   |
+---+---+   +---+---+
|   |   |   |   |   |
+---+---+   +---+---+
|                   |
+---+---+   +---+---+
|   |   |   |   |   |
+---+---+   +---+---+
|   |   |   |   |   |
+---+---+---+---+---+
  • Hinweis: Das Programm kann sehr kompakt geschrieben mit der Methode einer Zelle nachbar(dir)

Lösungsvorschlag

Lösungsvorschlag

a = [80, 114, 111, 98, 105, 101, 114, 101, 110, 32, 83, 105, 101, 32, 101, 115, 32, 100, 111, 99, 104, 32, 101, 114, 115, 116, 32, 109, 97, 108, 32, 115, 101, 108, 98, 101, 114, 46, 46, 46]
print("".join(map(lambda x:chr(x),a)))
  • Testen und verstehen Sie das Programm aufgabe2.py:
from laby import Laby
 
l = Laby(10,5)
for x in range(l.breite-1):
    l[x,0].zustand(0, True)
 
print(l)
  • Erweitern Sie das Programm so , dass folgendes Labyrinth produziert wird:
+---+---+---+---+---+---+---+---+---+---+
|                                       |
+---+---+---+---+---+---+---+---+---+---+
|                                       |
+---+---+---+---+---+---+---+---+---+---+
|                                       |
+---+---+---+---+---+---+---+---+---+---+
|                                       |
+---+---+---+---+---+---+---+---+---+---+
|                                       |
+---+---+---+---+---+---+---+---+---+---+

Lösungsvorschlag

Lösungsvorschlag

Packen Sie for-Schleife für die $x$-Koordinate in eine weiter for-Schleife für die $y$-Koordinate.

  • lehrkraefte/blc/informatik/glf24/laby/labyrintklasse.1747135926.txt.gz
  • Last modified: 2025/05/13 11:32
  • by Ivo Blöchliger