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:schleifen [2022/03/28 10:15] Olaf Schnürer [Aufgabe 3, Quadratzahlen ausgeben] |
lehrkraefte:snr:informatik:bruehl-2022:schleifen [2022/03/29 16:57] (current) Olaf Schnürer [Aufgabe 1, erste Erfahrungen mit ''while''-Schleifen] |
||
---|---|---|---|
Line 58: | Line 58: | ||
* Teste das folgende Programm. | * Teste das folgende Programm. | ||
- | * Was passiert, wenn du die letzte Zeile nicht einrückst? | + | * Was passiert |
* Was passiert, wenn du die beiden letzten Zeile miteinander vertauschst? | * Was passiert, wenn du die beiden letzten Zeile miteinander vertauschst? | ||
- | * Was passiert, wenn du die Zeile '' | + | * <del>Was passiert, wenn du die Zeile '' |
+ | </ | ||
<code python> | <code python> | ||
x = 0 | x = 0 | ||
while x < 20: | while x < 20: | ||
+ | print(x) | ||
x = x + 3 | x = x + 3 | ||
- | print(x) | ||
</ | </ | ||
Line 88: | Line 88: | ||
Schreibe ein Programm (mit einer '' | Schreibe ein Programm (mit einer '' | ||
+ | |||
+ | Hinweis: Schreibe zuerst ein Programm, dass alle Zahlen von 1 bis '' | ||
<code text> | <code text> | ||
1 | 1 | ||
Line 108: | Line 110: | ||
- | ===== Aufgabe 4, Turtle-Steuerung ===== | + | ===== Aufgabe 4, Turtle-Steuerung |
<WRAP center round todo 100%> | <WRAP center round todo 100%> | ||
Line 172: | Line 174: | ||
===== Lösungsvorschläge ===== | ===== Lösungsvorschläge ===== | ||
- | < | + | < |
+ | Es wird jeweils nur der eingerückte Code-Block mehrfach ausgeführt. Wie immer werden die Zeilen der Reihe nach von oben abgearbeitet. | ||
+ | * Nur einmal am Ende wird der Wert der Variablen '' | ||
+ | * Jeweils zuerst Ausgabe, dann Erhöhung um 3. Erste Ausgabe ist dann 0. | ||
+ | * Endlosschleife, | ||
+ | </ | ||
+ | |||
+ | <hidden Aufgabe 2> | ||
<code python> | <code python> | ||
+ | x = 5 | ||
+ | while x <= 19: | ||
+ | print(x) | ||
+ | x = x + 1 | ||
</ | </ | ||
</ | </ | ||
+ | <hidden Aufgabe 3> | ||
+ | <code python> | ||
+ | a = input(" | ||
+ | x = 1 | ||
+ | while x <= a: | ||
+ | print(x * x) | ||
+ | x = x + 1 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <hidden Aufgabe 4> | ||
+ | <code python> | ||
+ | from gturtle import * | ||
+ | makeTurtle() | ||
+ | |||
+ | eingabe = input(" | ||
+ | while eingabe != " | ||
+ | if eingabe == " | ||
+ | forward(50) | ||
+ | left(90) | ||
+ | elif eingabe == " | ||
+ | forward(50) | ||
+ | right(90) | ||
+ | else: | ||
+ | print(" | ||
+ | eingabe = input(" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <hidden Bonusaufgabe> | ||
+ | <code python> | ||
+ | a = input(" | ||
+ | summe = 0 | ||
+ | x = 1 | ||
+ | while x <= a: | ||
+ | summe = summe + x | ||
+ | x = x + 1 | ||
+ | print(" | ||
+ | print(a) | ||
+ | print(" | ||
+ | print(summe) | ||
+ | </ | ||
+ | </ | ||
===== Link zur Kursseite ===== | ===== Link zur Kursseite ===== |