Deprecated: Return type of WPCF7_FormTag::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/cscircles/dev/www/wordpress/wp-content/plugins/contact-form-7/includes/form-tag.php on line 396
Deprecated: Return type of WPCF7_FormTag::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/cscircles/dev/www/wordpress/wp-content/plugins/contact-form-7/includes/form-tag.php on line 388
Deprecated: Return type of WPCF7_FormTag::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/cscircles/dev/www/wordpress/wp-content/plugins/contact-form-7/includes/form-tag.php on line 382
Deprecated: Return type of WPCF7_FormTag::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/cscircles/dev/www/wordpress/wp-content/plugins/contact-form-7/includes/form-tag.php on line 400
Deprecated: Return type of WPCF7_Validation::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/cscircles/dev/www/wordpress/wp-content/plugins/contact-form-7/includes/validation.php on line 78
Deprecated: Return type of WPCF7_Validation::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/cscircles/dev/www/wordpress/wp-content/plugins/contact-form-7/includes/validation.php on line 72
Deprecated: Return type of WPCF7_Validation::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/cscircles/dev/www/wordpress/wp-content/plugins/contact-form-7/includes/validation.php on line 59
Deprecated: Return type of WPCF7_Validation::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/cscircles/dev/www/wordpress/wp-content/plugins/contact-form-7/includes/validation.php on line 82 2X: Zusätzliche Übungen | Computer Science Circles
[Distance Education in Python]
2X: Zusätzliche Übungen
Diese Lektion, bestehend aus Extra-Übungen zu den min- und max-Funktionen, ist optional. Wenn du ein Problem nicht gelöst bekommst, ist es kein großes Ding, wenn du es überspringst und später nochmal probierst. Du kannst dir jederzeit ansehen, welche Übungen du gelöst und welche du übersprungen hast, indem du auf die Seite Mein Fortschritt gehst.
Wir beginnen aber mit einer Übung zur ersten Lektion, Variablen. Sie ist etwas schwerer als die Übungen, die du bereits in der Lektion 1E: Fehler geschafft hast, also genau richtig für dich jetzt.
Vereinfachen eines komplexen Ausdrucks
Multiple-Choice-Übung: Vereinfachung
Welches ist eine Vereinfachung des folgenden Ausdrucks?
max(x - 3, min(x + 10, x + 5))
Korrekt! Da x + 5 immer kleiner ist als x + 10, können wir folgendes vereinfachen min(x + 10, x + 5) bis x + 5. Um dann nach außen zu arbeiten, muss der Gesamtausdruck folgendermaßen aussehen max(x - 3, x + 5). Da x + 5 immer das Maximum dieser zwei Zahlen ist, ist dies auch das Resultat.
Erschweren eines einfachen Ausdrucks
Auszahlungsrechner
Sortier-Durcheinander
In diesem letzten Problem geht es um die Sortierung von Zahlen - wenn auch auf einem recht seltsamen Weg. Es gibt deutlich bessere, einfachere und schnellere Sortierverfahren, die du nach diesen Einleitungslektionen lernen kannst.
Vergiss nicht, wenn du nicht mehr weiterkommst, nicht so schlimm, dann kannst du das Problem auch einfach überspringen.
Weiter geht's mit Lektion 3!
Dies ist kniffliges Problem. Schau dir zunächst das erste Jahr an. Wie groß ist die Bevölkerung nach einem Jahr mit 10% Wachstum? Die Zahl der neuen Personen beträgt 10% von 1000 = 0.1 * 1000 = 100. Nach einem Jahr gibt es also insgesamt (alt + neu) = 1100. Aber das Programm ist schon im ersten Jahr falsch:
gibt 100.0 statt der korrekten 1100.0. Siehst du, wie man die zweite Zeile um ein Zeichen verändern muss, damit die richtige Ausgabe 1100 entsteht?
Was ist max(-A, -B)?
Was ist min(A, B)+max(A, B)?
Teile das Problem in zwei Teile. Berechne zunächst das Maximum von 0.021 mal balance und 10. Dies ist der Betrag, solange er nicht balance übersteigt. Dann nutze min.
Dieser Code sortiert zunächst das Paar (x, y), dann (y, z) und dann wieder (x, y).