Benutzer-Werkzeuge

Webseiten-Werkzeuge


kicoku:kicokusommer2023

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
kicoku:kicokusommer2023 [2023/08/12 10:00] newokicoku:kicokusommer2023 [2023/11/24 19:42] (aktuell) – [KiCoKu Sommer 2023] newo
Zeile 1: Zeile 1:
- ====== KiCoKu Sommer 2023 ====== +====== KiCoKu Sommer 2023 ====== 
-===== Python =====+ 
 +Dieser Bereich basiert auf dem Buch "Teach your kids to code" from Bryson Pane und dem folgenden Udemy Kurs  
 +https://www.udemy.com/course/teach-your-kids-to-code\\ 
 +Dieser Kurs ist zwar auf Englisch, aber sehr leicht zu verstehen. 
 + 
 +Dauer: Mo. 28.8 bis Fr. 1.9 
 +Von 9:00 bis 13:00 
 + 
 +Teilnehmer: Felix G, Markus, Paul, Felix E  
 +===== Python Abschnitt 1 - Installation und Test =====
  
 Installation: [[https://www.python.org/downloads/windows/|Python für Windows]] Installation: [[https://www.python.org/downloads/windows/|Python für Windows]]
Zeile 52: Zeile 61:
 </code> </code>
  
 +===== Python Abschnitt 2 - Zeichnen =====
 ==== Erstes Ziel Sechs Eckige Spirale ==== ==== Erstes Ziel Sechs Eckige Spirale ====
 Unser erstes Ziel, eine sechseckige Spirale zeichnen lassen. Unser erstes Ziel, eine sechseckige Spirale zeichnen lassen.
Zeile 103: Zeile 113:
 Bei einer Schleife muss eine Einrückung gemacht werden Bei einer Schleife muss eine Einrückung gemacht werden
 <code> <code>
-SquareSpiral3.py+ViereckigeSpirale.py
 import turtle import turtle
 # Verwendung des Stifts von der turtle Library # Verwendung des Stifts von der turtle Library
Zeile 117: Zeile 127:
 === Aufgaben === === Aufgaben ===
 Beschleunigen des Skripts, einfuegen der Geschwindigkeit (nach turtle.Pen)\\ Beschleunigen des Skripts, einfuegen der Geschwindigkeit (nach turtle.Pen)\\
-t.speed(0)\\+<code>t.speed(0)</code>
 Ändern der Spirale\\ Ändern der Spirale\\
 Ändern des Abstands\\ Ändern des Abstands\\
     t.forward(2*x)\\     t.forward(2*x)\\
 Ändern der Farbe\\ Ändern der Farbe\\
-t.pencolor("red")\\+<code>t.pencolor("red")</code>
 Ändern der Lage\\ Ändern der Lage\\
     t.left(91)     t.left(91)
 +{{:kicoku:viereckigespirale.png?200|}}    
 +==== Kreise ====
 +<code>
 +# KreisSpirale.py
 +import turtle
 +# Verwendung des Stifts von der turtle Library
 +t = turtle.Pen()
 +t.speed(0)
 +t.pencolor("red")
 +# Mit der Schleife wird die Spirale gezeichnet
 +# x ist die Schleifenvariable, wird immer groesser und damit der Strich laenger, der gezeichnet wird
 +for x in range(100):
 +    # Zeichnen der Linie
 +    t.circle(x)
 +    # Drehen um 90 Grad
 +    t.left(91)
 +</code>
 +{{:kicoku:kreisspirale.png?200|}}
 +Ändern auf 90 und dann auf 60 Grad\\
 +Ändern der Farben auf andere Werte\\
 +"black" (schwarz)\\
 +"white" (weiss)\\
 +"red" (rot)\\
 +"green" (grün)\\
 +"blue" (blau)\\
 +"orange" (orange)\\
 +"yellow" (gelb)\\
 +"purple" (lila)\\
 +"pink" (pink)\\
 +"brown" (braun)\\
 +"gray" (grau)
 +==== Verschiedene Farben ====
 +<code>
 +# FaerbigeViereckigeSpirale.py
 +import turtle
 +t = turtle.Pen()
 +t.speed(0)
 +# Eine Liste von Farben
 +colors = ["red", "yellow", "blue", "green"]
 +for x in range(100):
 +    t.pencolor(colors[ x % 4 ])
 +    t.forward(2*x)
 +    t.left(91)
 +</code>
 +{{:kicoku:faerbigeviereckigespirale.png?200|}}
 +=== Aufgaben ===
 +Was passiert wenn die Farben geändert werden?\\
 +Was passiert wenn die Zahl 4 geändert wird?\\
 +Wie kann die Hintergrundfarbe geändert werden?\\
 +Wie können Kreise gezeichnet werden?\\
 +Was passiert wenn der Winkel von 91 auf 95 erhöht wird?
  
 +
 +=== Weitere Änderungen ===
 +Verwendung einer Variable\\
 +Mehr Farben\\
 +Andere Berechnungen\\
 +Eine zusätzliche Drehung am Ende
 +<code>
 +# FaerbigeViereckigeSpirale2.py
 +import turtle
 +t = turtle.Pen()
 +turtle.bgcolor("black")
 +t.speed(0)
 +# Eine Liste von Farben
 +sides = 10
 +colors = ["red", "yellow", "blue", "orange", "green",
 +          "purple", "gray", "white", "pink", "light blue"]
 +for x in range(360):
 +    t.pencolor(colors[ x % sides ])
 +    t.forward(x * 3 / sides + x)
 +    t.left(360/sides +1)
 +    t.width(x*sides/100)
 +    t.left(90)
 +</code>
 +{{:kicoku:faerbigeviereckigespirale2.png?200|}}
 +===== Python Abschnitt 3 - Variablen =====
 +==== Textvariablen ====
 +Ein Beispiel mit Textvariablen
 +<code>
 +# ThankYou.py
 +my_name = "Bryson"
 +my_age = 43
 +your_name = input("What is your name? ")
 +your_age = input("How old are you? ")
 +print("My name is", my_name, ", and I am", my_age, "years old.")
 +print("Your name is", your_name, ", and you are", your_age, ".")
 +print("Thank you for taking this course,", your_name, "!")
 +</code>
 +Bildschirmausgabe
 +<code>
 +What is your name? Wolfgang
 +How old are you? 52
 +My name is Bryson , and I am 43 years old.
 +Your name is Wolfgang , and you are 52 .
 +Thank you for taking this course, Wolfgang !
 +</code>
 +==== Zahlen Variablen ====
 +Beispiel Berechnung einer Pizzabestellung
 +<code>
 +#Pizza.py
 +
 +# Ask the person how many pizzas they want, get the number with eval()
 +number_of_pizzas = eval(input("How many pizzas do you want? "))
 +
 +# Ask for the menu cost of each pizza
 +cost_per_pizza = eval(input("How much does each pizza cost? "))
 +
 +# Calculate the total cost of the pizzas as our subtotal
 +subtotal = number_of_pizzas * cost_per_pizza
 +
 +# Wir geben 10% Trinkgeld
 +tip_rate = 0.1     # Store 10% as the decimal value 0.1
 +trinkgeld = subtotal * tip_rate
 +
 +# Add the sales tax to the subtotal for the final total
 +total = subtotal + trinkgeld
 +
 +# Show the user the total amount due, including tax
 +print("The total cost is €", total)
 +print("This includes €", subtotal, "for the pizza and")
 +print("€", trinkgeld, "als Trinkgeld.")
 +</code>
 +Bildschirmausgabe
 +<code>
 +How many pizzas do you want? 3
 +How much does each pizza cost? 8
 +The total cost is € 26.4
 +This includes € 24 for the pizza and
 +€ 2.4000000000000004 als Trinkgeld.
 +</code>
 +==== Wiederholte Zeichenausgabe ====
 +Wiederholte Zeichenausgabe
 +<code>
 +# SayMyName.py
 +
 +# Ask the user for their name
 +name = input("What is your name? ")
 +
 +# Print their name 100 times
 +for x in range(100):
 +    
 +    # Print their name followed by a space, not a new line
 +    print(name, end = " rules! ")
 +</code>
 +Bildschirmausgabe
 +<code>
 +What is your name? Wolfgang
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules! Wolfgang rules!
 +Wolfgang rules! Wolfgang rules! 
 +</code>
 +==== Text zeichnen ====
 +Textspirale
 +<code>
 +# SpiralMyName.py - prints a colorful spiral of the user's name
 +
 +import turtle               # Set up turtle graphics
 +t = turtle.Pen()
 +t.speed(0)
 +turtle.bgcolor("black")
 +colors = ["red", "yellow", "blue", "green"]
 +
 +# Ask the user's name using turtle's textinput pop-up window
 +your_name = turtle.textinput("Enter your name", "What is your name?")
 +
 +# Draw a spiral of the name on the screen, written 100 times
 +for x in range(100):
 +    t.pencolor( colors[ x % 4] )
 +    t.penup()
 +    t.forward( x * 4 )
 +    t.pendown()
 +    t.write(your_name, font = ("Times", int( (x + 4) / 4), "bold") )
 +    t.left(92)
 +</code>
 +{{:kicoku:spiralmyname.png?200|}}
 +==== Taschenrechner ====
 +<code>
 +print("MathHomework.py")
 +
 +# Ask the user to enter a math problem
 +problem = input("Enter a math problem, or 'q' to quit: ")
 +
 +# Keep going until the user enters 'q' to quit
 +while (problem != "q"):
 +    
 +    # Show the problem, and the answer using eval()
 +    print("The answer to ", problem, "is:", eval(problem) )
 +    
 +    # Ask for another math problem
 +    problem = input("Enter another math problem, or 'q' to quit: ")
 +    
 +    # This while loop will keep going until you enter 'q' to quit 
 +</code>
 +Bildschirmausgabe
 +<code>
 +MathHomework.py
 +Enter a math problem, or 'q' to quit: 5 + 2
 +The answer to  5 + 2 is: 7
 +Enter another math problem, or 'q' to quit: 5 / 2
 +The answer to  5 / 2 is: 2.5
 +Enter another math problem, or 'q' to quit: 5 // 2
 +The answer to  5 // 2 is: 2
 +Enter another math problem, or 'q' to quit: 5 % 2
 +The answer to  5 % 2 is: 1
 +Enter another math problem, or 'q' to quit: (4 + 2) * (2 + 2)
 +The answer to  (4 + 2) * (2 + 2) is: 24
 +Enter another math problem, or 'q' to quit: q
 +</code>
 +==== Eingabe für die färbige Spirale ====
 +<code>
 +# ColorSpiralInput.py
 +import turtle
 +t = turtle.Pen()
 +t.speed(0)
 +turtle.bgcolor("black")
 +# Set up a list of any 8 valid Python color names
 +colors = ["red", "yellow", "blue", "green",
 +          "orange", "purple", "white", "gray"]
 +# Ask the user for the number of sides
 +sides = int( turtle.numinput("Number of sides",
 +                             "How many sides do you want (1-8)?", 4, 1, 8))
 +# Draw a colorful spiral with the user-specified number of sides
 +for x in range(360):
 +    t.pencolor( colors[x % sides] )
 +    t.forward( x * 3 / sides + x)
 +    t.left(360 / sides + 1)
 +    t.width(x * sides / 200)
 +</code>
 +{{:kicoku:inputcolorspiral.png?200|}}
kicoku/kicokusommer2023.1691827238.txt.gz · Zuletzt geändert: 2023/08/12 10:00 von newo