python:turtle:programmverzweigungen
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| python:turtle:programmverzweigungen [2022/04/27 11:58] – lutz | python:turtle:programmverzweigungen [2024/04/09 07:00] (aktuell) – lutz | ||
|---|---|---|---|
| Zeile 24: | Zeile 24: | ||
| if < | if < | ||
| ... anweisungen ... | ... anweisungen ... | ||
| - | elif <bedinging2>: | + | elif <bedingung2>: |
| ... anweisungen ... | ... anweisungen ... | ||
| - | elif <bedinging3>: | + | elif <bedingung3>: |
| ... anweisungen ... | ... anweisungen ... | ||
| ... | ... | ||
| Zeile 39: | Zeile 39: | ||
| ^Operator ^Wirkung^ | ^Operator ^Wirkung^ | ||
| - | ^ > | größer | | + | ^ '' |
| - | ^ < | kleiner | | + | ^ '' |
| - | ^ >= | größer gleich | | + | ^ '' |
| - | ^ <= | kleiner gleich | | + | ^ '' |
| - | ^ == | gleich | | + | ^ '' |
| - | ^ != | ungleich | | + | ^ '' |
| + | Ausführlichere Informationen zum Thema findet ihr hier | ||
| + | |||
| + | [[python: | ||
| + | |||
| + | [[python: | ||
| + | |||
| + | |||
| + | Die folgenden drei Turtle-Programme sollen die drei Fälle demonstrieren: | ||
| + | |||
| + | <code python> | ||
| + | # Beispiel einseitige Alternative | ||
| + | from turtle import * | ||
| + | |||
| + | eingabe = textinput(" | ||
| + | |||
| + | # Zum Vergleich wird ein doppeltes = verwendet. | ||
| + | if eingabe == " | ||
| + | fd(200) | ||
| + | right(90) | ||
| + | fd(200) | ||
| + | right(90) | ||
| + | fd(200) | ||
| + | right(90) | ||
| + | fd(200) | ||
| + | |||
| + | print(" | ||
| + | </ | ||
| + | |||
| + | |||
| + | <code python> | ||
| + | # Beispiel zweiseitige Alternative | ||
| + | from turtle import * | ||
| + | |||
| + | eingabe = textinput(" | ||
| + | |||
| + | # Zum Vergleich wird ein doppeltes = verwendet. | ||
| + | if eingabe == " | ||
| + | fd(200) | ||
| + | right(90) | ||
| + | fd(200) | ||
| + | right(90) | ||
| + | fd(200) | ||
| + | right(90) | ||
| + | fd(200) | ||
| + | else: | ||
| + | fd(200) | ||
| + | right(120) | ||
| + | fd(200) | ||
| + | right(120) | ||
| + | fd(200) | ||
| + | |||
| + | print(" | ||
| + | </ | ||
| + | |||
| + | |||
| + | <code python> | ||
| + | # Beispiel Mehrfachverzweigung | ||
| + | from turtle import * | ||
| + | |||
| + | figur = textinput(" | ||
| + | stiftfarbe = textinput(" | ||
| + | fuellfarbe = textinput(" | ||
| + | |||
| + | if stiftfarbe == " | ||
| + | pencolor(" | ||
| + | elif stiftfarbe == " | ||
| + | pencolor(" | ||
| + | else: | ||
| + | pencolor(" | ||
| + | |||
| + | if fuellfarbe == " | ||
| + | fillcolor(" | ||
| + | elif fuellfarbe == " | ||
| + | fillcolor(" | ||
| + | else: | ||
| + | fillcolor(" | ||
| + | |||
| + | |||
| + | pensize(5) | ||
| + | |||
| + | if figur == " | ||
| + | begin_fill() | ||
| + | fd(200) | ||
| + | right(120) | ||
| + | fd(200) | ||
| + | right(120) | ||
| + | fd(200) | ||
| + | end_fill() | ||
| + | elif figur == " | ||
| + | begin_fill() | ||
| + | fd(200) | ||
| + | right(90) | ||
| + | fd(200) | ||
| + | right(90) | ||
| + | fd(200) | ||
| + | right(90) | ||
| + | fd(200) | ||
| + | end_fill() | ||
| + | else: | ||
| + | begin_fill() | ||
| + | fd(200) | ||
| + | right(60) | ||
| + | fd(200) | ||
| + | right(60) | ||
| + | fd(200) | ||
| + | right(60) | ||
| + | fd(200) | ||
| + | right(60) | ||
| + | fd(200) | ||
| + | right(60) | ||
| + | fd(200) | ||
| + | end_fill() | ||
| + | </ | ||
| + | |||
| + | |||
| + | Farbwähler: | ||
| + | |||
| + | **Aufgabe 12** | ||
| + | |||
| + | Teste die Beispielprogramme. Ergänze das Programm zur Mehrfachverzweigung um weitere Farben. | ||
| + | |||
| + | **Aufgabe 13** | ||
| + | |||
| + | Schreibe ein Programm bei dem zunächst folgende Eigenschaften abgefragt werden: | ||
| + | |||
| + | Figur: Dreieck, Quadrat, Sechseck | ||
| + | |||
| + | Stiftfarbe: rot, grün, blau | ||
| + | |||
| + | Füllfarbe: rot, grün, blau | ||
| + | |||
| + | entsprechend der Eingabe soll dann die entsprechende Figur gezeichnet werden. | ||
python/turtle/programmverzweigungen.1651053537.txt.gz · Zuletzt geändert: von lutz
