Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung
Nächste Überarbeitung
Vorherige Überarbeitung
gf_informatik:programmieren_ii [2025-10-30 08:54] – [Aufgaben D] hofgf_informatik:programmieren_ii [2026-04-08 18:16] (aktuell) hof
Zeile 1: Zeile 1:
 ====== Programmieren II: Python Grundlagen ====== ====== Programmieren II: Python Grundlagen ======
-<html><script type="module" src="https://bottom.ch/ksr/ed/bottom-editor.js"></script></html>+<html><script type="module" src="https://bottom.ch/editor/stable/bottom-editor.js"></script></html>
    
 ===== Von Struktogrammen zu Python ===== ===== Von Struktogrammen zu Python =====
Zeile 145: Zeile 145:
 == Teil I== == Teil I==
  
-<code python>+<html><bottom-editor>
 x = int(input('Gib eine Zahl ein')) x = int(input('Gib eine Zahl ein'))
 y = int(input('Gib eine Zahl ein')) y = int(input('Gib eine Zahl ein'))
 print(x + y) print(x + y)
-</code>+</bottom-editor></html>
  
 == Teil II== == Teil II==
  
 Einfach: Einfach:
-<code python>+<html><bottom-editor>
 x = int(input('Gib eine Zahl ein')) x = int(input('Gib eine Zahl ein'))
 y = int(input('Gib eine Zahl ein')) y = int(input('Gib eine Zahl ein'))
Zeile 162: Zeile 162:
 else: else:
     print(y)     print(y)
-</code>+</bottom-editor></html>
  
  
 === Aufgabe A2 === === Aufgabe A2 ===
-<code python>+<html><bottom-editor>
 n = int(input("Gib Startzahl von Countdown ein!")) n = int(input("Gib Startzahl von Countdown ein!"))
  
Zeile 174: Zeile 174:
  
 print("Los!") print("Los!")
-</code>+</bottom-editor></html>
  
 === Aufgabe A3 === === Aufgabe A3 ===
 == Teil I == == Teil I ==
-<code python>+<html><bottom-editor>
 a = int(input("Gib Zahl ein")) a = int(input("Gib Zahl ein"))
 b = int(input("Gib Zahl ein")) b = int(input("Gib Zahl ein"))
Zeile 187: Zeile 187:
 print(c) print(c)
 print(a) print(a)
-</code>+</bottom-editor></html>
  
 == Teil II == == Teil II ==
-<code python>+<html><bottom-editor>
 n = int(input("Gib Zahl ein")) n = int(input("Gib Zahl ein"))
 summe = 0 summe = 0
Zeile 198: Zeile 198:
     summe = summe + zahl     summe = summe + zahl
 print(summe) print(summe)
-</code>+</bottom-editor></html>
  
 === Aufgabe A4 === === Aufgabe A4 ===
Zeile 492: Zeile 492:
 Beispiel: Werden $23$ und $5$ eingegeben, so ist die Ausgabe: "23 : 5 = 4 Rest 3" Beispiel: Werden $23$ und $5$ eingegeben, so ist die Ausgabe: "23 : 5 = 4 Rest 3"
  
-<nodisp 2>+<nodisp 1>
 ++++Lösungen Aufgaben B| ++++Lösungen Aufgaben B|
  
Zeile 499: Zeile 499:
 === Aufgabe B1 === === Aufgabe B1 ===
  
-<code python>+<html><bottom-editor> 
 +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></html> 
 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><bottom-editor>
 name = input("Wie heisst du?") name = input("Wie heisst du?")
 city = input("Wo wohnst du?") city = input("Wo wohnst du?")
-age  = input("Wie alt bist du?")+age  = int(input("Wie alt bist du?"))
 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></html>
  
 === Aufgabe B3 === === Aufgabe B3 ===
Zeile 527: Zeile 529:
 === Aufgabe B4 === === Aufgabe B4 ===
  
-<code python>+<html><bottom-editor> 
 +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></html>
  
 === Aufgabe B5 === === Aufgabe B5 ===
  
 Zählen von $0$ bis $9$: Zählen von $0$ bis $9$:
-<code python>+<html><bottom-editor>
 i = 0 i = 0
 while i < 10: while i < 10:
     print(i)     print(i)
     i = i + 1     i = i + 1
-</code>+</bottom-editor></html> 
 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><bottom-editor>
 i = 0 i = 0
 while i < 100: while i < 100:
     print(i)     print(i)
     i = i + 1     i = i + 1
-</code>+</bottom-editor></html> 
 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><bottom-editor>
 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("I am " + str(my_age_in_years) + " years old."+print(f"I am {my_age_in_yearsyears old."
-print("I am " + str(my_age_in_days) + " day old."+print(f"I am {my_age_in_daysday old."
-print("I am " + str(my_age_in_hours) + " hours old."+print(f"I am {my_age_in_hourshours old."
-print("I am " + str(my_age_in_seconds) + " seconds old."+print(f"I am {my_age_in_secondsseconds old."
-</code>+</bottom-editor></html>
  
 ++++ ++++
Zeile 594: Zeile 600:
 {{ : gf_informatik:spiralen_duo.png?250 |}} {{ : gf_informatik:spiralen_duo.png?250 |}}
  
-<nodisp 2>+<nodisp 0>
 ++++Tipps| ++++Tipps|
  
Zeile 621: Zeile 627:
 Schicke das Endresultat per Teams der Lehrperson. Schicke das Endresultat per Teams der Lehrperson.
  
-<nodisp 2>+<nodisp 1>
 ++++Lösungen Aufgaben C| ++++Lösungen Aufgaben C|
  
Zeile 628: Zeile 634:
 === Aufgabe C1 === === Aufgabe C1 ===
  
-<code python+<html><bottom-editor layout="split"
-from gturtle import *+from turtle import *
 turi = Turtle() turi = Turtle()
-turi.hideTurtle()+turi.hideturtle()
  
-0 +sides 4 
-while i < 4+while sides > 0
-    turi.forward(200)+    turi.forward(100)
     turi.left(90)     turi.left(90)
-</code>+    sides = sides - 1 
 +</bottom-editor></html>
  
 === Aufgabe C2 === === Aufgabe C2 ===
  
-<code python+<html><bottom-editor layout="split"
-from gturtle import *+from turtle import *
  
 monika = Turtle() monika = Turtle()
-monika.hideTurtle()+monika.hideturtle()
  
-monika.setPos(-200,0) +monika.teleport(-100,0) 
-0 +length 100 
-while i < 39+while length > 0
-    monika.forward(10*i)+    monika.forward(length)
     monika.left(90)     monika.left(90)
-    i + 1+    length length - 5
          
-monika.setPos(200,0) +monika.teleport(100,0) 
-0 +length 100 
-while i < 96+while length > 0
-    monika.forward(4*i)+    monika.forward(length)
     monika.left(90)     monika.left(90)
-    i + 1 +    length length - 2 
-</code>+</bottom-editor></html>
  
 === Aufgabe C3 === === Aufgabe C3 ===
  
-<code python+<html><bottom-editor layout="split"
-from gturtle import *+from turtle import *
 t = Turtle() t = Turtle()
-t.hideTurtle()+t.hideturtle()
  
-+radius 50 
-l = 5 +while radius > 0
-while i < 150+    t.circle(radius180
-    t.rightArc(l,20+    radius = radius - 4 
-    l + 2 # increase radius  +</bottom-editor></html>
-    i = i + 1 +
-</code>+
  
 === Aufgabe C4 === === Aufgabe C4 ===
  
-<code python> +<html><bottom-editor layout="split"> 
-</code>+from turtle import *
  
 +kurt = Turtle()
 +kurt.speed(8)
 +
 +side = 100      # Länge der kürzeren Seite
 +side_ratio = 2  # Soviel länger ist die längere Seite
 +step_size = 5   # Soviel wird die Länge kürzer pro Durchgang
 +
 +while side > 0:
 +    kurt.forward(side * side_ratio)
 +    kurt.left(90)
 +    kurt.forward(side)
 +    kurt.left(90)
 +    side = side - step_size
 +</bottom-editor></html>
 ++++ ++++
 </nodisp> </nodisp>
Zeile 739: 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 [[#zufallszahlen|Zufallsgenerator]] von Python, um die beiden Zahlen, die addiert werden sollen, zufällig zu wählen.
  
 Dazu musst du das //random//-Modul einbinden. Dazu musst du das //random//-Modul einbinden.
Zeile 772: Zeile 791:
 Mache eine Kopie von deinem Mathe-Quiz. Erweitere deinen Code nun so, dass neben der Addition auch Subtraktionen und Multiplikationen vorkommen können. Die Division sollte weggelassen werden, da es dort schnell Aufgaben gibt, die man kaum lösen kann. Welche der drei Operationen an der Reihe ist, soll ebenfalls der Zufall entscheiden. Mache eine Kopie von deinem Mathe-Quiz. Erweitere deinen Code nun so, dass neben der Addition auch Subtraktionen und Multiplikationen vorkommen können. Die Division sollte weggelassen werden, da es dort schnell Aufgaben gibt, die man kaum lösen kann. Welche der drei Operationen an der Reihe ist, soll ebenfalls der Zufall entscheiden.
  
-<nodisp 2>+<nodisp 1>
 ++++Lösungen Aufgaben D| ++++Lösungen Aufgaben D|
  
Zeile 779: Zeile 798:
 === Aufgabe D1 === === Aufgabe D1 ===
  
-<code python>+<html><bottom-editor>
 age = int(input("Gib dein Alter ein")) age = int(input("Gib dein Alter ein"))
  
Zeile 788: Zeile 807:
 else: else:
     print("Sirup!")     print("Sirup!")
-</code>+</bottom-editor></html>
  
 === Aufgabe D2 === === Aufgabe D2 ===
  
-<code python>+<html><bottom-editor>
 x = int(input("Gib eine Zahl ein")) x = int(input("Gib eine Zahl ein"))
  
Zeile 801: Zeile 820:
 else: else:
     print("Negativ!")     print("Negativ!")
-</code>+</bottom-editor></html>
  
 === Aufgabe D3 === === Aufgabe D3 ===
  
-<code python>+<html><bottom-editor layout="split">
 from turtle import * from turtle import *
  
 turi = Turtle() turi = Turtle()
 +turi.speed(8)
 turi.hideturtle() turi.hideturtle()
  
Zeile 840: Zeile 860:
  
 turi.end_fill()  turi.end_fill() 
-</code>+</bottom-editor></html>
  
 === Aufgabe D4 === === Aufgabe D4 ===
  
-<code python+<html><bottom-editor
-</code>+import random 
 + 
 +questions = 0 
 +correct = 0 
 + 
 +while questions < 10: 
 +    questions = questions + 1 
 + 
 +    x = random.randint(1, 20) 
 +    y = random.randint(1, 20) 
 +    result = x + y 
 +    answer = int(input(f'Was ergibt {x} + {y} ?')) 
 +    if answer == result: 
 +        correct = correct + 1 
 + 
 +print(f'Du hast {correct} von 10 Aufgaben richtig gelöst!'
 +</bottom-editor></html>
  
 ++++ ++++
 </nodisp> </nodisp>
  • gf_informatik/programmieren_ii.1761814493.txt.gz
  • Zuletzt geändert: 2025-10-30 08:54
  • von hof