Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Nächste Überarbeitung | Vorherige Überarbeitung | ||
| textadventure:iteration [2026/05/29 09:53] – angelegt celandir | textadventure:iteration [2026/05/29 10:03] (aktuell) – celandir | ||
|---|---|---|---|
| Zeile 10: | Zeile 10: | ||
| print(ding) | print(ding) | ||
| </ | </ | ||
| + | |||
| + | <div todo> | ||
| + | Analysiere den vorstehenden Quelltext, indem du ihn mit dem Debugger ausführst. Lasse dir die Variablen anzeigen. | ||
| + | </ | ||
| + | |||
| + | Wie du siehst, erhält die Variable '' | ||
| + | |||
| + | <div todo> | ||
| + | Baue nun in dein Adventure die Möglichkeit ein, sich das Inventar anzeigen zu lassen. An welcher Stelle passt das gut? Wie muss man das in deinen Code einfügen? | ||
| + | </ | ||
| + | |||
| + | Eine mögliche Lösung könnte wie folgt aussehen: | ||
| + | |||
| + | <file python iteration.py[enable_line_numbers=" | ||
| + | inventar = [" | ||
| + | |||
| + | def waldlichtung(): | ||
| + | gute_antwort = False | ||
| + | while not gute_antwort: | ||
| + | print(" | ||
| + | print(" | ||
| + | wahl = input(" | ||
| + | if wahl == " | ||
| + | print(" | ||
| + | for ding in inventar: | ||
| + | print(ding) | ||
| + | elif wahl == " | ||
| + | gute_antwort = True | ||
| + | flussufer() | ||
| + | elif wahl == " | ||
| + | gute_antwort = True | ||
| + | verlasseneHuette() | ||
| + | else: | ||
| + | dunklerWald() | ||
| + | |||
| + | def flussufer(): | ||
| + | gute_antwort = False | ||
| + | while not gute_antwort: | ||
| + | print(" | ||
| + | print(" | ||
| + | wahl = input(" | ||
| + | if wahl == " | ||
| + | print(" | ||
| + | for ding in inventar: | ||
| + | print(ding) | ||
| + | elif wahl == " | ||
| + | gute_antwort = True | ||
| + | waldlichtung() | ||
| + | elif wahl == " | ||
| + | gute_antwort = True | ||
| + | holzsteg() | ||
| + | else: | ||
| + | dunklerWald() | ||
| + | |||
| + | def holzsteg(): | ||
| + | gute_antwort = False | ||
| + | while not gute_antwort: | ||
| + | print(" | ||
| + | if " | ||
| + | print(" | ||
| + | wahl = input(" | ||
| + | if wahl == " | ||
| + | print(" | ||
| + | for ding in inventar: | ||
| + | print(ding) | ||
| + | elif wahl == " | ||
| + | gute_antwort = True | ||
| + | flussufer() | ||
| + | else: | ||
| + | print(" | ||
| + | wahl = input(" | ||
| + | if wahl == " | ||
| + | print(" | ||
| + | for ding in inventar: | ||
| + | print(ding) | ||
| + | elif wahl == " | ||
| + | gute_antwort = True | ||
| + | flussufer() | ||
| + | elif wahl == " | ||
| + | gute_antwort = True | ||
| + | inventar.append(" | ||
| + | holzsteg() | ||
| + | |||
| + | def verlasseneHuette(): | ||
| + | gute_antwort = False | ||
| + | while not gute_antwort: | ||
| + | print(" | ||
| + | print(" | ||
| + | wahl = input(" | ||
| + | if wahl == " | ||
| + | print(" | ||
| + | for ding in inventar: | ||
| + | print(ding) | ||
| + | elif wahl == " | ||
| + | gute_antwort = True | ||
| + | waldlichtung() | ||
| + | elif wahl == " | ||
| + | if " | ||
| + | print(" | ||
| + | else: | ||
| + | print(" | ||
| + | else: | ||
| + | dunklerWald() | ||
| + | |||
| + | def dunklerWald(): | ||
| + | print(" | ||
| + | print(" | ||
| + | |||
| + | waldlichtung() | ||
| + | </ | ||
| + | |||
| + | Nächste Lektion: (TBD) | ||