Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lehrkraefte:snr:informatik:python:loops [2021/09/15 18:16] Olaf Schnürer [Bonus-Aufgaben] |
lehrkraefte:snr:informatik:python:loops [2021/09/22 14:41] (current) Olaf Schnürer [Verschachtelte for-Schleifen] |
||
---|---|---|---|
Line 100: | Line 100: | ||
<code python> | <code python> | ||
for i in range(3): | for i in range(3): | ||
- | print(" | + | print(" |
for j in range(3): | for j in range(3): | ||
print(" | print(" | ||
print(" | print(" | ||
print(" | print(" | ||
- | print(" | + | print(" |
</ | </ | ||
Line 161: | Line 161: | ||
</ | </ | ||
+ | 2dNP bis hier 22.09.2021 | ||
===== Bonus-Aufgaben ===== | ===== Bonus-Aufgaben ===== | ||
- | |||
- | <WRAP round todo> | ||
- | Schreibe ein Programm, dass die [[https:// | ||
- | Sie gibt an, wie sich eine idealisierte Kaninchenpopulation [[https:// | ||
- | </ | ||
- | |||
<WRAP round todo> | <WRAP round todo> | ||
Line 185: | Line 180: | ||
</ | </ | ||
+ | <WRAP round todo> | ||
+ | Schreibe ein Programm, dass die [[https:// | ||
+ | Sie gibt an, wie sich eine idealisierte Kaninchenpopulation [[https:// | ||
+ | |||
+ | Wie schnell wächst diese Folge? Vergleiche mit der Folge, deren $n$-tes Glied durch $x_n=\left(\frac{1+\sqrt{5}}2\right)^n$ gegeben ist, indem du für jedes $n$ den Quotienten $\frac{f_n}{x_n}$ berechnest, wobei $f_n$ das $n$-te Glied der Fibonacci-Folge ist. | ||
+ | <hidden Hinweis> | ||
+ | Will man die Werte zweier Variablen tauschen, braucht man eigentlich eine Hilfsvariable: | ||
+ | <code python> | ||
+ | x = 1 | ||
+ | y = 2 | ||
+ | print(x, y) | ||
+ | z = x | ||
+ | x = y | ||
+ | y = z | ||
+ | print(x, y) | ||
+ | </ | ||
+ | Python ist aber sehr benutzerfreundlich und erlaubt Folgendes: | ||
+ | <code python> | ||
+ | x = 1 | ||
+ | y = 2 | ||
+ | print(x, y) | ||
+ | x, y = y, x | ||
+ | print(x, y) | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
===== Einige Lösungsvorschläge ===== | ===== Einige Lösungsvorschläge ===== | ||
Line 203: | Line 224: | ||
print(" | print(" | ||
x = x * (1 + zunahme_prozent / 100) | x = x * (1 + zunahme_prozent / 100) | ||
- | </ | ||
- | </ | ||
- | |||
- | <hidden Summe der ersten $n$ Zahlen> | ||
- | <code python> | ||
- | n = 10 | ||
- | summe = 0 | ||
- | ausgabe = "" | ||
- | for i in range(1, | ||
- | summe = summe + i | ||
- | ausgabe = ausgabe + " | ||
- | # Alternativ: ausgabe = ausgabe + " | ||
- | print(ausgabe + " | ||
</ | </ | ||
</ | </ | ||
Line 235: | Line 243: | ||
s = s + " | s = s + " | ||
print(s) | print(s) | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <hidden Summe der ersten $n$ Zahlen> | ||
+ | <code python> | ||
+ | n = 10 | ||
+ | summe = 0 | ||
+ | ausgabe = "" | ||
+ | for i in range(1, | ||
+ | summe = summe + i | ||
+ | ausgabe = ausgabe + " | ||
+ | # Alternativ: ausgabe = ausgabe + " | ||
+ | print(ausgabe + " | ||
</ | </ | ||
</ | </ |