Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lehrkraefte:snr:informatik:bruehl-2022:auswahl [2022/03/17 08:14] Olaf Schnürer |
lehrkraefte:snr:informatik:bruehl-2022:auswahl [2022/03/21 10:25] (current) Olaf Schnürer [Lösungsvorschläge und Tafelanschriebe] |
||
---|---|---|---|
Line 383: | Line 383: | ||
</ | </ | ||
- | <hidden Aufgabe 2> | + | <hidden Aufgabe 2: Zufällige Bewegung> |
{{: | {{: | ||
<code python> | <code python> | ||
Line 403: | Line 403: | ||
</ | </ | ||
- | < | + | < |
+ | Das Programm wartet auf einen Tastendruck und speichert diesen in der Variablen '' | ||
+ | |||
+ | Der Befehl '' | ||
+ | Der Befehl '' | ||
+ | |||
+ | Es geht auch nur mit '' | ||
<code python> | <code python> | ||
+ | from gturtle import * # Die ersten beiden Zeilen dienen nur dazu, dass der Befehl getKeyWait() bekannt ist. | ||
+ | makeTurtle() | ||
+ | |||
+ | taste = getKeyWait() | ||
+ | print(taste) | ||
+ | |||
+ | if taste == " | ||
+ | print(" | ||
+ | if taste == " | ||
+ | print(" | ||
+ | if taste == " | ||
+ | print(" | ||
+ | if taste == " | ||
+ | print(" | ||
+ | if taste == " | ||
+ | print(" | ||
+ | if taste != " | ||
+ | print(" | ||
+ | |||
+ | dispose() | ||
</ | </ | ||
+ | </ | ||
+ | |||
+ | <hidden Aufgabe 4: Ferngesteuerte Turtle> | ||
+ | <code python> | ||
+ | from gturtle import * | ||
+ | makeTurtle(" | ||
+ | |||
+ | taste = " " | ||
+ | |||
+ | # Die folgende sogenannte " | ||
+ | # ähnlich wie eine repeat-Schleife: | ||
+ | # eingerückte Code-Block wird solange wiederholt | ||
+ | # ausgeführt, | ||
+ | # englisch WHILE = deutsch SOLANGE | ||
+ | s = 10 | ||
+ | |||
+ | while taste != " | ||
+ | taste = getKeyWait() | ||
+ | |||
+ | if taste == " | ||
+ | forward(s) | ||
+ | elif taste == " | ||
+ | left(60) | ||
+ | elif taste == " | ||
+ | backward(s) | ||
+ | elif taste == " | ||
+ | right(60) | ||
+ | elif taste == " | ||
+ | s = s + 1 | ||
+ | elif taste == " | ||
+ | s = s - 1 | ||
+ | elif taste == " | ||
+ | winkel = input(" | ||
+ | right(winkel) | ||
+ | elif taste == " | ||
+ | home() | ||
+ | elif taste != " | ||
+ | print(" | ||
+ | |||
+ | dispose() | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <hidden Aufgabe 5: Quiz> | ||
+ | <code python> | ||
+ | n = 0 # Anzahl korrekter Antworten. | ||
+ | |||
+ | a = input(" | ||
+ | if a == 26: # Achtung, manche haben hier a == " | ||
+ | print(" | ||
+ | n = n + 1 | ||
+ | else: | ||
+ | print(" | ||
+ | | ||
+ | b = input(" | ||
+ | if b == 8 or b == 9: | ||
+ | print(" | ||
+ | n = n + 1 | ||
+ | else: | ||
+ | print(" | ||
+ | |||
+ | c = input(" | ||
+ | if c == " | ||
+ | print(" | ||
+ | n = n + 1 | ||
+ | else: | ||
+ | print(" | ||
+ | |||
+ | print(" | ||
+ | print(n) | ||
+ | |||
+ | if n > 2: | ||
+ | print(" | ||
+ | elif n == 0: | ||
+ | print(" | ||
+ | </ | ||
+ | | ||
+ | Und hier die Bonus-Variante (die ersten beiden Fragen per '' | ||
+ | <code python> | ||
+ | n = 0 # Anzahl korrekter Antworten. | ||
+ | v = 0 # Anzahl falsche Versuche | ||
+ | |||
+ | eingabeStimmt = 0 | ||
+ | repeat 3: | ||
+ | if eingabeStimmt == 0: | ||
+ | a = input(" | ||
+ | if a == 26: | ||
+ | print(" | ||
+ | n = n + 1 | ||
+ | eingabeStimmt = 1 | ||
+ | else: | ||
+ | print(" | ||
+ | v = v + 1 | ||
+ | if eingabeStimmt == 0: | ||
+ | print(" | ||
+ | |||
+ | print(20 * " | ||
+ | eingabeStimmt = 0 | ||
+ | repeat 3: | ||
+ | if eingabeStimmt == 0: | ||
+ | b = input(" | ||
+ | if b == 8 or b == 9: | ||
+ | print(" | ||
+ | n = n + 1 | ||
+ | eingabeStimmt = 1 | ||
+ | else: | ||
+ | print(" | ||
+ | v = v + 1 | ||
+ | if eingabeStimmt == 0: | ||
+ | print(" | ||
+ | |||
+ | # Und nun die Variante mit der while-Schleife | ||
+ | |||
+ | |||
+ | print(20 * " | ||
+ | nochVersuche = 3 # Anzahl der Versuche, die der Antwortende noch hat. | ||
+ | |||
+ | while nochVersuche > 0: | ||
+ | c = input(" | ||
+ | nochVersuche = nochVersuche - 1 | ||
+ | if c == " | ||
+ | print(" | ||
+ | n = n + 1 | ||
+ | nochVersuche = 0 | ||
+ | else: | ||
+ | print(" | ||
+ | v = v + 1 | ||
+ | if c != " | ||
+ | print(" | ||
+ | |||
+ | |||
+ | print(20 * " | ||
+ | print(" | ||
+ | print(n) | ||
+ | print(" | ||
+ | print(v) | ||
+ | |||
+ | if n == 3 and v == 0: | ||
+ | print(" | ||
+ | else: | ||
+ | print(" | ||
+ | </ | ||
</ | </ | ||