Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung Nächste Überarbeitung | Vorherige Überarbeitung | ||
| gf_informatik:programmieren_ii [2025-11-08 14:24] – [Zusatzaufgabe C (Uhr)] hof | gf_informatik:programmieren_ii [2026-04-08 18:16] (aktuell) – hof | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| ====== Programmieren II: Python Grundlagen ====== | ====== Programmieren II: Python Grundlagen ====== | ||
| - | < | + | < |
| ===== Von Struktogrammen zu Python ===== | ===== Von Struktogrammen zu Python ===== | ||
| Zeile 145: | Zeile 145: | ||
| == Teil I== | == Teil I== | ||
| - | <code python> | + | <html>< |
| x = int(input(' | x = int(input(' | ||
| y = int(input(' | y = int(input(' | ||
| print(x + y) | print(x + y) | ||
| - | </code> | + | </bottom-editor></ |
| == Teil II== | == Teil II== | ||
| Einfach: | Einfach: | ||
| - | <code python> | + | <html>< |
| x = int(input(' | x = int(input(' | ||
| y = int(input(' | y = int(input(' | ||
| Zeile 162: | Zeile 162: | ||
| else: | else: | ||
| print(y) | print(y) | ||
| - | </code> | + | </bottom-editor></ |
| === Aufgabe A2 === | === Aufgabe A2 === | ||
| - | <code python> | + | <html>< |
| n = int(input(" | n = int(input(" | ||
| Zeile 174: | Zeile 174: | ||
| print(" | print(" | ||
| - | </code> | + | </bottom-editor></ |
| === Aufgabe A3 === | === Aufgabe A3 === | ||
| == Teil I == | == Teil I == | ||
| - | <code python> | + | <html>< |
| a = int(input(" | a = int(input(" | ||
| b = int(input(" | b = int(input(" | ||
| Zeile 187: | Zeile 187: | ||
| print(c) | print(c) | ||
| print(a) | print(a) | ||
| - | </code> | + | </bottom-editor></ |
| == Teil II == | == Teil II == | ||
| - | <code python> | + | <html>< |
| n = int(input(" | n = int(input(" | ||
| summe = 0 | summe = 0 | ||
| Zeile 198: | Zeile 198: | ||
| summe = summe + zahl | summe = summe + zahl | ||
| print(summe) | print(summe) | ||
| - | </code> | + | </bottom-editor></ |
| === Aufgabe A4 === | === Aufgabe A4 === | ||
| Zeile 499: | Zeile 499: | ||
| === Aufgabe B1 === | === Aufgabe B1 === | ||
| - | <code python> | + | <html>< |
| + | from math import sqrt | ||
| # 1. | # 1. | ||
| print(7777+8888) | print(7777+8888) | ||
| Zeile 508: | Zeile 509: | ||
| # 4. | # 4. | ||
| print(sqrt(1764)) # ja, ist Quadratzahl | print(sqrt(1764)) # ja, ist Quadratzahl | ||
| - | </code> | + | </bottom-editor></ |
| Bemerkung: Einzelne Werte können auch in Variablen gespeichert werden. Dann kann mit den Variablen gerechnet werden. Es macht den Code aber nur länger. | Bemerkung: Einzelne Werte können auch in Variablen gespeichert werden. Dann kann mit den Variablen gerechnet werden. Es macht den Code aber nur länger. | ||
| === Aufgabe B2 === | === Aufgabe B2 === | ||
| - | <code python> | + | <html>< |
| name = input(" | name = input(" | ||
| city = input(" | city = input(" | ||
| - | age = input(" | + | age = int(input(" |
| print(name + " wohnt in " + city + " und ist " + str(age) + " Jahre alt!") | print(name + " wohnt in " + city + " und ist " + str(age) + " Jahre alt!") | ||
| - | </code> | + | </bottom-editor></ |
| === Aufgabe B3 === | === Aufgabe B3 === | ||
| Zeile 527: | Zeile 529: | ||
| === Aufgabe B4 === | === Aufgabe B4 === | ||
| - | <code python> | + | <html>< |
| + | from math import sqrt | ||
| x = 7 | x = 7 | ||
| x = x*2 | x = x*2 | ||
| Zeile 538: | Zeile 541: | ||
| print(x) | print(x) | ||
| - | </code> | + | </bottom-editor></ |
| === Aufgabe B5 === | === Aufgabe B5 === | ||
| Zählen von $0$ bis $9$: | Zählen von $0$ bis $9$: | ||
| - | <code python> | + | <html>< |
| i = 0 | i = 0 | ||
| while i < 10: | while i < 10: | ||
| print(i) | print(i) | ||
| i = i + 1 | i = i + 1 | ||
| - | </code> | + | </bottom-editor></ |
| Zählen von $0$ bis $99$, es muss nur $10$ durch $9$ ersetzt werden. | Zählen von $0$ bis $99$, es muss nur $10$ durch $9$ ersetzt werden. | ||
| - | <code python> | + | |
| + | <html>< | ||
| i = 0 | i = 0 | ||
| while i < 100: | while i < 100: | ||
| print(i) | print(i) | ||
| i = i + 1 | i = i + 1 | ||
| - | </code> | + | </bottom-editor></ |
| Beachte, Code kann auch z.B. mit `while i <= 9` geschrieben werden. Die Notation `while i < 10` hat aber den Vorteil, dass man sofort sieht, wieviele Zahlen ($10$) angezeigt werden. Natürlich muss dafür $i$ bei $0$ starten. | Beachte, Code kann auch z.B. mit `while i <= 9` geschrieben werden. Die Notation `while i < 10` hat aber den Vorteil, dass man sofort sieht, wieviele Zahlen ($10$) angezeigt werden. Natürlich muss dafür $i$ bei $0$ starten. | ||
| === Aufgabe B6 === | === Aufgabe B6 === | ||
| - | <code python> | + | <html>< |
| my_age_in_years = 14 | my_age_in_years = 14 | ||
| Zeile 567: | Zeile 573: | ||
| my_age_in_seconds = my_age_in_hours * 3600 | my_age_in_seconds = my_age_in_hours * 3600 | ||
| - | print(" | + | print(f"I am {my_age_in_years} years old." |
| - | print(" | + | print(f"I am {my_age_in_days} day old." |
| - | print(" | + | print(f"I am {my_age_in_hours} hours old." |
| - | print(" | + | print(f"I am {my_age_in_seconds} seconds old." |
| - | </code> | + | </bottom-editor></ |
| ++++ | ++++ | ||
| Zeile 628: | Zeile 634: | ||
| === Aufgabe C1 === | === Aufgabe C1 === | ||
| - | <code python> | + | <html>< |
| from turtle import * | from turtle import * | ||
| turi = Turtle() | turi = Turtle() | ||
| Zeile 638: | Zeile 644: | ||
| turi.left(90) | turi.left(90) | ||
| sides = sides - 1 | sides = sides - 1 | ||
| - | </code> | + | </bottom-editor></ |
| === Aufgabe C2 === | === Aufgabe C2 === | ||
| - | <code python> | + | <html>< |
| from turtle import * | from turtle import * | ||
| Zeile 661: | Zeile 667: | ||
| monika.left(90) | monika.left(90) | ||
| length = length - 2 | length = length - 2 | ||
| - | </code> | + | </bottom-editor></ |
| === Aufgabe C3 === | === Aufgabe C3 === | ||
| - | <code python> | + | <html>< |
| from turtle import * | from turtle import * | ||
| t = Turtle() | t = Turtle() | ||
| Zeile 674: | Zeile 680: | ||
| t.circle(radius, | t.circle(radius, | ||
| radius = radius - 4 | radius = radius - 4 | ||
| - | </code> | + | </bottom-editor></ |
| === Aufgabe C4 === | === Aufgabe C4 === | ||
| - | < | + | < |
| - | </iframe> | + | from turtle import * |
| - | </ | + | |
| + | kurt = Turtle() | ||
| + | kurt.speed(8) | ||
| + | |||
| + | side = 100 # Länge der kürzeren Seite | ||
| + | side_ratio | ||
| + | step_size | ||
| + | |||
| + | while side > 0: | ||
| + | kurt.forward(side * side_ratio) | ||
| + | kurt.left(90) | ||
| + | kurt.forward(side) | ||
| + | kurt.left(90) | ||
| + | side = side - step_size | ||
| + | </bottom-editor></ | ||
| ++++ | ++++ | ||
| </ | </ | ||
| Zeile 738: | Zeile 758: | ||
| == Schritt 2 == | == Schritt 2 == | ||
| - | Erweitere nun dein Mathe-Quiz. In diesem soll die Aufgabe per Zufall generiert werden. Nutze den Zufallsgenerator von Python, um die beiden Zahlen, die addiert werden sollen, zufällig zu wählen. | + | Erweitere nun dein Mathe-Quiz. In diesem soll die Aufgabe per Zufall generiert werden. Nutze den [[# |
| Dazu musst du das // | Dazu musst du das // | ||
| Zeile 778: | Zeile 798: | ||
| === Aufgabe D1 === | === Aufgabe D1 === | ||
| - | <code python> | + | <html>< |
| age = int(input(" | age = int(input(" | ||
| Zeile 787: | Zeile 807: | ||
| else: | else: | ||
| print(" | print(" | ||
| - | </code> | + | </bottom-editor></ |
| === Aufgabe D2 === | === Aufgabe D2 === | ||
| - | <code python> | + | <html>< |
| x = int(input(" | x = int(input(" | ||
| Zeile 800: | Zeile 820: | ||
| else: | else: | ||
| print(" | print(" | ||
| - | </code> | + | </bottom-editor></ |
| === Aufgabe D3 === | === Aufgabe D3 === | ||
| - | <code python> | + | <html>< |
| from turtle import * | from turtle import * | ||
| turi = Turtle() | turi = Turtle() | ||
| + | turi.speed(8) | ||
| turi.hideturtle() | turi.hideturtle() | ||
| Zeile 839: | Zeile 860: | ||
| turi.end_fill() | turi.end_fill() | ||
| - | </code> | + | </bottom-editor></ |
| === Aufgabe D4 === | === Aufgabe D4 === | ||
| - | <code python> | + | <html>< |
| - | </code> | + | import random |
| + | |||
| + | questions = 0 | ||
| + | correct = 0 | ||
| + | |||
| + | while questions < 10: | ||
| + | questions = questions + 1 | ||
| + | |||
| + | x = random.randint(1, | ||
| + | y = random.randint(1, | ||
| + | result = x + y | ||
| + | answer = int(input(f' | ||
| + | if answer == result: | ||
| + | correct = correct + 1 | ||
| + | |||
| + | print(f' | ||
| + | </ | ||
| ++++ | ++++ | ||
| </ | </ | ||