Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung | |||
| gf_informatik:funktionen:aufgaben_d [2026-05-08 06:32] – [1. Aufgaben ND – Funktionen für Fortgeschrittene] gra | gf_informatik:funktionen:aufgaben_d [2026-05-08 06:36] (aktuell) – [ND3 – Fibonacci-Spirale] gra | ||
|---|---|---|---|
| Zeile 69: | Zeile 69: | ||
| </ | </ | ||
| + | ==== Lösungen ==== | ||
| + | <nodisp 2> | ||
| + | ++++Lösungen zu Aufgaben ND:| | ||
| + | |||
| + | === ND1 === | ||
| + | <code python> | ||
| + | def hotel_preise2(personen, | ||
| + | doppelzimmer = personen // 2 | ||
| + | einzelzimmer = personen % 2 | ||
| + | tage = [" | ||
| + | starttag = tage.index(anreisetag) | ||
| + | preis = 0 | ||
| + | nacht = 0 | ||
| + | | ||
| + | while nacht < naechte: | ||
| + | aktueller_tag_index = (starttag + nacht) % 7 | ||
| + | aktueller_tag = tage[aktueller_tag_index] | ||
| + | | ||
| + | if aktueller_tag in [" | ||
| + | preis = preis + doppelzimmer * 200 + einzelzimmer * 150 | ||
| + | else: | ||
| + | preis = preis + doppelzimmer * 140 + einzelzimmer * 120 | ||
| + | | ||
| + | nacht = nacht + 1 | ||
| + | | ||
| + | return preis | ||
| + | |||
| + | # Reise 1: 2 Personen, 2 Nächte ab Freitag: Preis = 400 | ||
| + | print(hotel_preise2(2, | ||
| + | # Reise 2: 3 Personen, 4 Nächte ab Mittwoch: Preis = 1220 | ||
| + | print(hotel_preise2(3, | ||
| + | # Reise 3: 1 Person, 10 Nächte ab Donnerstag: Preis = 1320 | ||
| + | print(hotel_preise2(1, | ||
| + | </ | ||
| + | |||
| + | === ND2 === | ||
| + | <code python> | ||
| + | from gturtle import * | ||
| + | paula = Turtle() | ||
| + | |||
| + | def rgb_dot(red, | ||
| + | hexcodes = [" | ||
| + | colorcode = hexcodes[red] + hexcodes[green] + hexcodes[blue] | ||
| + | paula.setPenColor(colorcode) | ||
| + | paula.dot(40) | ||
| + | | ||
| + | paula.right(90) | ||
| + | xpos = 0 | ||
| + | ypos = 0 | ||
| + | |||
| + | for r in range(6): | ||
| + | |||
| + | for g in range(6): | ||
| + | | ||
| + | for b in range(6): | ||
| + | paula.setPos(xpos, | ||
| + | rgb_dot(r, | ||
| + | xpos = xpos + 50 | ||
| + | | ||
| + | xpos = xpos - 300 | ||
| + | ypos = ypos - 50 | ||
| + | | ||
| + | xpos = xpos + 350 | ||
| + | ypos = 0 | ||
| + | </ | ||
| + | |||
| + | === ND3 === | ||
| + | <code python> | ||
| + | from gturtle import * | ||
| + | leonardo = Turtle() | ||
| + | |||
| + | def fibonacci(n): | ||
| + | fibs = [] | ||
| + | s1 = 0 | ||
| + | s2 = 1 | ||
| + | i = 0 | ||
| + | while i < n: | ||
| + | fibs.append(s1) | ||
| + | s = s1 + s2 | ||
| + | s1 = s2 | ||
| + | s2 = s | ||
| + | i = i + 1 | ||
| + | return fibs | ||
| + | |||
| + | def viertelkreis(radius, | ||
| + | leonardo.setFillColor(farbe) | ||
| + | leonardo.startPath() | ||
| + | leonardo.rightArc(radius, | ||
| + | leonardo.right(90) | ||
| + | leonardo.forward(radius) | ||
| + | leonardo.fillPath() | ||
| + | leonardo.right(180) | ||
| + | leonardo.forward(radius) | ||
| + | leonardo.right(90) | ||
| + | |||
| + | def fibo_spirale(n): | ||
| + | fibos = fibonacci(n) | ||
| + | i = 0 | ||
| + | while i < len(fibos): | ||
| + | radius = fibos[i] * 10 | ||
| + | if i % 2 == 0: | ||
| + | viertelkreis(radius," | ||
| + | else: | ||
| + | viertelkreis(radius," | ||
| + | i = i + 1 | ||
| + | |||
| + | def fibo_spirale2(n, | ||
| + | fibos = fibonacci(n) | ||
| + | i = 0 | ||
| + | while i < len(fibos): | ||
| + | radius = fibos[i] * 10 | ||
| + | viertelkreis(radius, | ||
| + | i = i + 1 | ||
| + | |||
| + | leonardo.right(90) | ||
| + | farben = [" | ||
| + | fibo_spirale2(9, | ||
| + | </ | ||
| + | |||
| + | ++++ | ||
| + | </ | ||