{"id":5569,"date":"2012-09-13T16:42:41","date_gmt":"2012-09-13T20:42:41","guid":{"rendered":"http:\/\/cscircles.cemc.uwaterloo.ca\/?page_id=5569"},"modified":"2023-11-02T05:13:41","modified_gmt":"2023-11-02T09:13:41","slug":"7b-de","status":"publish","type":"page","link":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/7b-de\/","title":{"rendered":"7B: Mathematik"},"content":{"rendered":"<p><em>Lektion 7 besteht aus drei Teilen A, B und C, die in beliebiger Reihenfolge bearbeitet werden k\u00f6nnen.<\/em><\/p>\n<p>Bislang haben wir mathematische Berechnungen angestellt, indem wir Pythons Operatoren <code>+<\/code>, <code>-<\/code>, <code>*<\/code>, <code>\/<\/code> und die Funktionen <code>max<\/code> und <code>min<\/code> verwendet haben. In dieser Lektion werden wir einige weitere Operatoren und Funktionen sehen, und wir werden lernen, wie wir komplexere Berechnungen anstellen k\u00f6nnen.<\/p>\n<h2>Mathematische Operatoren<\/h2>\n<p>Wir haben bereits gesehen, wie man Operatoren verwendet, um zu addieren (<code>a + b<\/code>), subtrahieren (<code>a - b<\/code>), multiplizieren (<code>a * b<\/code>) und dividieren (<code>a \/ b<\/code>). Wir werden jetzt mehr \u00fcber drei zus\u00e4tzliche Operatoren lernen.<\/p>\n<ul>\n<li><strong>Der Potenz-Operator<\/strong> <code>a ** b<\/code> berechnet <code>a<sup>b<\/sup><\/code> (<code>a<\/code>, das insgesamt <code>b<\/code> mal mit sich selbst multipliziert wird). Zum Beispiel ergibt <code>2 ** 3<\/code> das Ergebnis <code>8<\/code> (n\u00e4mlich 2*2*2).<\/li>\n<li><strong>Der ganzzahlige Divisions-Operator<\/strong> <code>a \/\/ b<\/code> berechnet <code><\/code>den \"Quotienten\" von <code>a<\/code> dividiert durch <code>b<\/code> und rundet das Ergebnis auf die n\u00e4chst-niedrigere ganze Zahl. Sind <code style=\"font-style: inherit;\">a<\/code> und\u00a0<code style=\"font-style: inherit;\">b<\/code>\u00a0beides positive Zahlen (gr\u00f6\u00dfer 0), bedeutet das, dass alles hinter dem Komma gestrichen wird.\u00a0So hat zum Beispiel <code>14 \/\/ 3<\/code> das Ergebnis <code>4<\/code>.<\/li>\n<li><strong>Der Teilungsrest-Operator<\/strong> <code>a % b<\/code> (auch: <strong>Modulo-Operator<\/strong>) berechnet den Rest, wenn\u00a0<code>a<\/code> durch <code>b<\/code> dividiert wird. So hat zum Beispiel <code>14 % 3<\/code> das Ergebnis <code>2<\/code>.<\/li>\n<\/ul>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform0\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox0'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>Die Operatoren f\u00fcr\u00a0 Potenzen, ganzzahlige Division und Teilungsreste<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 84px;'><textarea wrap='off' name='usercode0' id='usercode0'  cols=10 rows=3 readonly='readonly'  style = 'height : 84px;'  class='pyboxCode RO'>\nprint(2 ** 3)\nprint(14 \/\/ 3)\nprint(14 % 3)<\/textarea><\/div>\n<div id='pbhistory0' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit0' value=' '\/><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(0)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(0,'N')\" ><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse0\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"0\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"a3511b91883033660b56dabaf0837468\"\/>\n<div id='pbresults0' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit0\").value = \"Run program\";document.getElementById(\"inputInUse0\").value = \"N\";<\/script>\n<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform1\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox1'>\n<img title='You have not yet completed this problem.' src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/icon.png' class='pycheck'\/><div class=\"heading\"><span class='type'>Coding Exercise: <\/span><span class='title'>Eggsactly<\/span><\/div>Eierkartons haben Platz f\u00fcr exakt 12 Eier. Schreibe ein Programm, das eine ganzzahlige Anzahl von Eiern aus dem <code>input()<\/code> liest und dann zwei Zahlen ausgibt: wieviele Kartons mit diesen Eiern gef\u00fcllt werden k\u00f6nnen, und wieviele Eier \u00fcbrig sein werden. Zum Beispiel ist die Ausgabe, die <code>27<\/code> Eiern entspricht<\/p>\n<pre>2\n3<\/pre>da <code>27<\/code> Eier <code>2<\/code> Kartons f\u00fcllen, wobei <code>3<\/code> Eier \u00fcbrig bleiben. <a class=\"hintlink\"  id=\"hintlink2\">Hinweis<\/a><\/p>\n<div class=\"helpOuter\" style=\"display: none;\"><div class=\"helpInner\"><div style=\"text-align: center\">You need to create an account and log in to ask a question.<\/div><\/div><\/div><div class='pyboxTextwrap pyboxCodewrap RW resizy'  style='height: 526px;'><textarea wrap='off' name='usercode1' id='usercode1'  cols=10 rows=20   class='pyboxCode RW'>\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory1' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput1\">You may enter input for the program in the box below.<div class=\"pyboxTextwrap resizy\" style=\"height: 102px;\" ><textarea wrap=\"off\" name=\"userinput\" class=\"pyboxInput\" cols=10 rows=4><\/textarea><\/div><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit1' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch1\" value=\"Input Switch\" onclick=\"pbInputSwitch(1,'N')\" ><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(1)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(1,'N')\" ><\/td>\n<\/tr><\/table><select id='pbSelect1' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(1,'7b.eggs')\" >History<\/option>\n<option name='help' data-pbonclick=\"helpClick(1);\" >Help<\/option>\n<\/select><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse1\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"1\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"92f7490555a7d3bfb78ae267eb295628\"\/>\n<div id='pbresults1' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(1);});pbInputSwitch(1,\"N\");<\/script>\n<\/p>\n<p>Der Modulo-Operator wird f\u00fcr eine Vielzahl an Aufgaben verwendet. Er kann verwendet werden, um Fragen wie die folgenden zu beantworten:<\/p>\n<ul>\n<li>Wenn es jetzt 10 Uhr ist, wie sp\u00e4t wird es in 100 Stunden sein? (Hier wird der Rest einer Division durch 12 ben\u00f6tigt; es muss also modulo 12 gerechnet werden.)<\/li>\n<li>Wird das Jahr 2032 ein Schaltjahr sein? (<a href=\"http:\/\/de.wikipedia.org\/wiki\/Schaltjahr\">Hier muss modulo 4, 100 und 400 gerechnet werden.<\/a>)<\/li>\n<\/ul>\n<p>Das Testen von Schaltjahren ist ein Beispiel f\u00fcr die \u00dcberpr\u00fcfung von Teilbarkeit. In der n\u00e4chsten \u00dcbung bitten wir dich, ein Programm zu schreiben, das ganz allgemein die Teilbarkeit \u00fcberpr\u00fcft.<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform3\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox3'>\n<img title='You have not yet completed this problem.' src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/icon.png' class='pycheck'\/><div class=\"heading\"><span class='type'>Coding Exercise: <\/span><span class='title'>Teilbarkeit<\/span><\/div>Schreibe ein Programm, das zwei positive ganze Zahlen <code>a<\/code> und <code>b<\/code> in unterschiedlichen Zeilen einliest. Wenn <code>a<\/code> durch <code>b<\/code> teilbar ist, gib die\u00a0 Botschaft \"divisible\" (also teilbar) aus. Wenn nicht, gib die Botschaft \"not divisible\" (also nicht teilbar) aus. Zum Beispiel, f\u00fcr folgende Eingabe:<\/p>\n<pre>14\n3<\/pre>sollte das Programm \"not divisible\" ausgeben. <a class=\"hintlink\"  id=\"hintlink4\">Hinweis<\/a><div class=\"helpOuter\" style=\"display: none;\"><div class=\"helpInner\"><div style=\"text-align: center\">You need to create an account and log in to ask a question.<\/div><\/div><\/div><div class='pyboxTextwrap pyboxCodewrap RW resizy'  style='height: 526px;'><textarea wrap='off' name='usercode3' id='usercode3'  cols=10 rows=20   class='pyboxCode RW'>\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory3' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput3\">You may enter input for the program in the box below.<div class=\"pyboxTextwrap resizy\" style=\"height: 102px;\" ><textarea wrap=\"off\" name=\"userinput\" class=\"pyboxInput\" cols=10 rows=4><\/textarea><\/div><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit3' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch3\" value=\"Input Switch\" onclick=\"pbInputSwitch(3,'N')\" ><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(3)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(3,'N')\" ><\/td>\n<\/tr><\/table><select id='pbSelect3' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(3,'7b.divisible')\" >History<\/option>\n<option name='help' data-pbonclick=\"helpClick(3);\" >Help<\/option>\n<\/select><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse3\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"3\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"37b874bc7fc3646c27ae69eeca562e3f\"\/>\n<div id='pbresults3' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(3);});pbInputSwitch(3,\"N\");<\/script>\n<\/p>\n<h2>Mathematische Funktionen<\/h2>\n<p>Python kann die meisten mathematischen Funktionen berechnen, die sich auf einem wissenschaftlichen Taschenrechner befinden.<\/p>\n<ul>\n<li><code>sqrt(x)<\/code> berechnet die Quadratwurzel der Zahl <code>x<\/code>.<\/li>\n<li><code>exp(x)<\/code> und <code>log(x)<\/code> sind die Exponentialfunktion und der nat\u00fcrliche Logarithmus.<\/li>\n<li><code>sin(x)<\/code>, <code>cos(x)<\/code>, <code>tan(x)<\/code> und andere trigonometrische Funktionen sind verf\u00fcgbar.<\/li>\n<li><code>pi<\/code>, die mathematische Konstante <code>3.1415...<\/code>, geh\u00f6rt ebenfalls dazu.<\/li>\n<\/ul>\n<p><table class='pywarn'><tr><td class='pywarnleft'><img src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/warning.png'\/><\/td><td class='pywarnright'><span> Wenn du die trigonometrischen Funktionen von Python verwendest, musst du den Winkel <code>x<\/code> als Radiant angeben, nicht in Grad. <\/span><\/td><\/table><\/p>\n<p>Python beinhaltet eine derart gro\u00dfe Menge an Funktionen, dass sie in Gruppen organisiert werden, die <em>Module<\/em> genannt werden. Die oben gezeigten Funktionen geh\u00f6ren zum <code>math<\/code> Modul. Bevor du eine Funktion eines Moduls verwendest, musst du das Modul <em>importieren<\/em>, wie du es im Beispiel unten siehst. Um eine Funktion eines Moduls zu verwenden, musst du den Modulnamen eingeben, dann einen Punkt, und dann den Namen der Funktion.<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform5\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox5'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>Funktionen des Moduls <code>math<\/code> verwenden<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 136px;'><textarea wrap='off' name='usercode5' id='usercode5'  cols=10 rows=5 readonly='readonly'  style = 'height : 136px;'  class='pyboxCode RO'>\nimport math\nprint(math.pi)\ne = math.exp(1)\nprint(e)\nprint(math.sqrt(3), math.tan(math.pi \/ 3))<\/textarea><\/div>\n<div id='pbhistory5' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit5' value=' '\/><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(5)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(5,'N')\" ><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse5\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"5\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"f6885f61429ba7ceee96a03033a06e45\"\/>\n<div id='pbresults5' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit5\").value = \"Run program\";document.getElementById(\"inputInUse5\").value = \"N\";<\/script>\n<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform6\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox6'>\n<img title='You have not yet completed this problem.' src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/icon.png' class='pycheck'\/><div class=\"heading\"><span class='type'>Coding Exercise: <\/span><span class='title'>Pizza Circles<\/span><\/div>Deine Freunde haben ihre quadratischen Pizzas gegessen und bestellen jetzt eine runde Pizza. Schreibe ein Programm, um die Fl\u00e4che dieser kreisrunden Pizza zu berechnen. Die Eingabe ist eine <code>Gleitpunktzahl<\/code> <em>r<\/em>, die den Radius in cm angibt. Die Ausgabe sollte die Fl\u00e4che in cm<sup>2<\/sup> sein, die mit der\u00a0 Formel <em>A=pi*r<sup>2<\/sup><\/em> berechnet wird. Verwende Pythons <code>pi<\/code> Konstante, anstatt <code>3.1415...<\/code> zu tippen.<div class=\"helpOuter\" style=\"display: none;\"><div class=\"helpInner\"><div style=\"text-align: center\">You need to create an account and log in to ask a question.<\/div><\/div><\/div><div class='pyboxTextwrap pyboxCodewrap RW resizy'  style='height: 526px;'><textarea wrap='off' name='usercode6' id='usercode6'  cols=10 rows=20   class='pyboxCode RW'>\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory6' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput6\">You may enter input for the program in the box below.<div class=\"pyboxTextwrap resizy\" style=\"height: 102px;\" ><textarea wrap=\"off\" name=\"userinput\" class=\"pyboxInput\" cols=10 rows=4><\/textarea><\/div><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit6' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch6\" value=\"Input Switch\" onclick=\"pbInputSwitch(6,'N')\" ><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(6)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(6,'N')\" ><\/td>\n<\/tr><\/table><select id='pbSelect6' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(6,'7b.pizza')\" >History<\/option>\n<option name='help' data-pbonclick=\"helpClick(6);\" >Help<\/option>\n<\/select><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse6\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"6\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"4d9be21907c4cb660da29f75120d531d\"\/>\n<div id='pbresults6' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(6);});pbInputSwitch(6,\"N\");<\/script>\n<\/p>\n<p><em><form class=\"pbform\" action=\"#\" id=\"pbform7\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox7'>\n<img title='You have not yet completed this problem.' src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/icon.png' class='pycheck'\/><div class=\"heading\"><span class='type'>Coding Exercise: <\/span><span class='title'>Geometrisches Mittel<\/span><\/div>Das geometrische Mittel<\/em> zweier Zahlen <code>a<\/code> und <code>b<\/code> ist die Zahl<\/p>\n<p style=\"text-align: center;\"><img src='https:\/\/s0.wp.com\/latex.php?latex=%5Csqrt%7Bab%7D&#038;bg=T&#038;fg=000000&#038;s=2' alt='\\sqrt{ab}' title='\\sqrt{ab}' class='latex' \/><\/p>\n<p>Schreibe ein Programm, das zwei Zeilen von positiven <code>Gleitpunktzahlen<\/code> aus dem Input liest, und ihr geometrisches Mittel ausgibt. <br\/> Beispiel: Wenn die Eingabe folgendes ist:<\/p>\n<pre>5.0\n20.0<\/pre>dann sollte die Ausgabe <code>10.0<\/code>. sein.<div class=\"helpOuter\" style=\"display: none;\"><div class=\"helpInner\"><div style=\"text-align: center\">You need to create an account and log in to ask a question.<\/div><\/div><\/div><div class='pyboxTextwrap pyboxCodewrap RW resizy'  style='height: 526px;'><textarea wrap='off' name='usercode7' id='usercode7'  cols=10 rows=20   class='pyboxCode RW'>\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory7' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput7\">You may enter input for the program in the box below.<div class=\"pyboxTextwrap resizy\" style=\"height: 102px;\" ><textarea wrap=\"off\" name=\"userinput\" class=\"pyboxInput\" cols=10 rows=4><\/textarea><\/div><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit7' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch7\" value=\"Input Switch\" onclick=\"pbInputSwitch(7,'N')\" ><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(7)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(7,'N')\" ><\/td>\n<\/tr><\/table><select id='pbSelect7' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(7,'7b.geometricmean')\" >History<\/option>\n<option name='help' data-pbonclick=\"helpClick(7);\" >Help<\/option>\n<\/select><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse7\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"7\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"433fd9b3b38fb2d328110db5196df913\"\/>\n<div id='pbresults7' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(7);});pbInputSwitch(7,\"N\");<\/script>\n<\/p>\n<h2>Alles zusammenf\u00fcgen<\/h2>\n<p>Wie du in der vorhergehenden \u00dcbung schon gesehen hast, kann man mathematische Ausdr\u00fccke zusammenbauen, indem man Operatoren kombiniert. Python wertet die Ausdr\u00fccke aus, indem es dieselbe <a href=\"http:\/\/de.wikipedia.org\/wiki\/Operatorrangfolge\">Operatorrangfolge <\/a>verwendet, die wir im Matheunterricht gelernt haben:<\/p>\n<p style=\"padding-left: 30px;\"><strong>K<\/strong>lammern zuerst, dann <strong>E<\/strong>xponenten, darauf folgen <strong>D<\/strong>ivision und <strong>M<\/strong>ultiplikation, dann schlie\u00dflich <strong>A<\/strong>ddition und <strong>S<\/strong>ubtraktion,<\/p>\n<p>die wir uns mit dem Akronym \"KEDMAS\" merken k\u00f6nnen. Division von Ganzzahlen und Modulo passen in die Kategorie \"Division und Multiplikation\". So wird zum Beispiel der Ausdruck<\/p>\n<pre>3 * (1 + 2) ** 2 % 4<\/pre>ausgewertet, indem die Addition in Klammern ausgef\u00fchrt wird (1 + 2 = 3), dann der Exponent (3 ** 2 = 9) , dann die Multiplikation (3 * 9 = 27), und schlie\u00dflich Modulo, so dass das Ergebnis 27 % 4 = <code>3<\/code> lautet.<\/p>\n<p><div class='pybox modeNeutral' id='pybox8'>\n<img title='You have not yet completed this problem.' src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/icon.png' class='pycheck'\/><div class=\"heading\"><span class='type'>Short Answer Exercise: <\/span><span class='title'>Operatorrangfolge<\/span><\/div>Berechne den Wert des Python-Ausdrucks<\/p>\n<pre>6 - 52 \/\/ 5 ** 2<\/pre><label for=\"pyShortAnswer8\">Your answer (enter a number): <\/label><input type=\"text\" onkeypress=\"{if (event.keyCode==13) pbShortCheck(8)}\" id=\"pyShortAnswer8\"><div class=\"pyboxbuttons\"><input type=\"hidden\" name=\"type\" value=\"number\"\/><input type=\"hidden\" name=\"correct\" value=\"4\"\/><input type=\"hidden\" name=\"slug\" value=\"7b.bedmas\"\/><input type=\"hidden\" name=\"lang\" value=\"\"\/><input type='submit' style='margin:5px;' value='Check answer' onClick = 'pbShortCheck(8)'\/><\/div><div class=\"pbresults\" id=\"pyShortResults8\"><\/div><div class=\"epilogue\">Correct!<\/div><\/div>\n<p><em>Division von ganzen Zahlen mit negativen Zahlen<\/em>: Die Ausdr\u00fccke <code>a \/\/ b<\/code> und <code>int(a \/ b)<\/code> sind gleichwertig, wenn <code>a<\/code> und <code>b<\/code> positiv sind. Wenn jedoch <code>a<\/code> negativ ist, verwendet <code>a \/\/ b<\/code> die Option \"gegen negativ unendlich runden\" und <code>int(a \/ b)<\/code> verwendet \"gegen 0 runden.\"<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform9\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox9'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>Ganzzahlige Division mit negativen Zahlen <div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 58px;'><textarea wrap='off' name='usercode9' id='usercode9'  cols=10 rows=2 readonly='readonly'  style = 'height : 58px;'  class='pyboxCode RO'>\nprint((-10) \/\/ 3, int((-10) \/ 3)) # different\nprint((-12) \/\/ 2, int((-12) \/ 2)) # gleiches Ergebnis, nur weil 2 die -12 genau teilt.<\/textarea><\/div>\n<div id='pbhistory9' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit9' value=' '\/><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(9)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(9,'N')\" ><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse9\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"9\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"464727d042bd9df042823307bac7c1b3\"\/>\n<div id='pbresults9' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit9\").value = \"Run program\";document.getElementById(\"inputInUse9\").value = \"N\";<\/script>\n<\/p>\n<h2>Ganze Zahlen und Gleitpunktzahlen<\/h2>\n<p>Das Resultat eines mathematischen Ausdrucks ist eine Zahl. Wie wir schon <a href=\"http:\/\/cscircles.cemc.uwaterloo.ca\/4-de\/\">zuvor<\/a> gesehen haben, kann eine Zahl in Python einen dieser zwei Typen haben:\u00a0<code>int<\/code> oder <code>float<\/code>. Der Typ <code>int<\/code> repr\u00e4sentiert ganze Zahlen (Englisch: <em>integers<\/em>), sowohl positive als auch negative, die so gro\u00df sein k\u00f6nnen, wie du willst.<\/p>\n<p><table class='pywarn'><tr><td class='pywarnleft'><img src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/warning.png'\/><\/td><td class='pywarnright'><span> Python akzeptiert keine Zahlen, die in der Form <code>1 000 000<\/code> oder <code>1,000,000<\/code> geschrieben werden. Tippe statt dessen <code>1000000.<\/code> <\/span><\/td><\/table><\/p>\n<p>Der Typ <code>float<\/code> repr\u00e4sentiert Dezimalzahlen - wobei die echten mathematischen Dezimalzahlen im Computer nur angen\u00e4hert werden k\u00f6nnen; deshalb sprechen wir lieber von Gleitpunktzahlen (Englisch: <em>floating point numbers<\/em>). Genau wie ein einfacher Taschenrechner f\u00fcr die Zahl 1\/3 \u00a0den N\u00e4herungswert <code>0.33333333<\/code> abspeichert, macht es auch Python mit Dezimalzahlen. <table class='pywarn'><tr><td class='pywarnleft'><img src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/warning.png'\/><\/td><td class='pywarnright'><span> Weil Python N\u00e4herungswerte von Dezimalzahlen verwendet, kann es sein, dass manche Gleichungen, die mathematisch korrekt sind, unter Umst\u00e4nden in Python nicht gelten.  <form class=\"pbform\" action=\"#\" id=\"pbform10\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox10'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div><div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 110px;'><textarea wrap='off' name='usercode10' id='usercode10'  cols=10 rows=4 readonly='readonly'  style = 'height : 110px;'  class='pyboxCode RO'>\nimport math\ns = math.sqrt(2) * math.sqrt(2)\nprint(s == 2)\nprint(s)<\/textarea><\/div>\n<div id='pbhistory10' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit10' value=' '\/><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(10)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(10,'N')\" ><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse10\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"10\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"b416006b57a6ea47b55211769d6b5292\"\/>\n<div id='pbresults10' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit10\").value = \"Run program\";document.getElementById(\"inputInUse10\").value = \"N\";<\/script>\n  <form class=\"pbform\" action=\"#\" id=\"pbform11\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox11'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div><div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 84px;'><textarea wrap='off' name='usercode11' id='usercode11'  cols=10 rows=3 readonly='readonly'  style = 'height : 84px;'  class='pyboxCode RO'>\ns = 0.1 + 0.1 + 0.1\nprint('s equals 0.3?', s == 0.3)\nprint('s =', s)<\/textarea><\/div>\n<div id='pbhistory11' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit11' value=' '\/><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(11)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(11,'N')\" ><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse11\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"11\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"152b3da4460191b4c80831387738e623\"\/>\n<div id='pbresults11' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit11\").value = \"Run program\";document.getElementById(\"inputInUse11\").value = \"N\";<\/script>\n  Aus diesem Grund ist es wichtig, einen gewissen Spielraum f\u00fcr diese N\u00e4herungswerte zuzulassen, wenn du Zahlen des\u00a0<code>float<\/code> Typs vergleichst. So wird im internen Auswertungssystem dieser Seite eine <code>float<\/code>-Ausgabe als korrekt bewertet, wenn sie <a class=\"hintlink\"  id=\"hintlink12\"><em>n\u00e4herungsweise<\/em><\/a> gleich der erwarteten Antwort ist. <\/span><\/td><\/table><\/p>\n<p>Wir beenden diese Lektion mit einigen \u00dcbungen.<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform13\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox13'>\n<img title='You have not yet completed this problem.' src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/icon.png' class='pycheck'\/><div class=\"heading\"><span class='type'>Coding Exercise: <\/span><span class='title'>Klammer-Test<\/span><\/div>Du sollst drei ganze Zahlen nehmen, die ersten zwei Zahlen addieren und anschlie\u00dfend das Resultat mit der dritten Zahl multiplizieren. Schreibe ein Programm, das die drei Zahlen einliest und das korrekte Ergebnis ausgibt. <a class=\"hintlink\"  id=\"hintlink14\">Tipp<\/a><div class=\"helpOuter\" style=\"display: none;\"><div class=\"helpInner\"><div style=\"text-align: center\">You need to create an account and log in to ask a question.<\/div><\/div><\/div><div class='pyboxTextwrap pyboxCodewrap RW resizy'  style='height: 526px;'><textarea wrap='off' name='usercode13' id='usercode13'  cols=10 rows=20   class='pyboxCode RW'>\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory13' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput13\">You may enter input for the program in the box below.<div class=\"pyboxTextwrap resizy\" style=\"height: 102px;\" ><textarea wrap=\"off\" name=\"userinput\" class=\"pyboxInput\" cols=10 rows=4><\/textarea><\/div><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit13' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch13\" value=\"Input Switch\" onclick=\"pbInputSwitch(13,'N')\" ><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(13)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(13,'N')\" ><\/td>\n<\/tr><\/table><select id='pbSelect13' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(13,'7b.skill')\" >History<\/option>\n<option name='help' data-pbonclick=\"helpClick(13);\" >Help<\/option>\n<\/select><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse13\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"13\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"f449b1d593875010c3689f907862436b\"\/>\n<div id='pbresults13' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(13);});pbInputSwitch(13,\"N\");<\/script>\n<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform15\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox15'>\n<img title='You have not yet completed this problem.' src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/icon.png' class='pycheck'\/><div class=\"heading\"><span class='type'>Coding Exercise: <\/span><span class='title'>A Feat With Feet<\/span><\/div>F\u00fcr dieses Programm ist die Eingabe eine Gleitpunktzahl, die eine H\u00f6he gemessen in Fu\u00df darstellt. Schreibe ein Programm, das die \u00e4quivalente H\u00f6he in Zentimetern ausgibt und dabei folgende Formel verwendet: 1 Fu\u00df = 30.48 cm. Wenn zum Beispiel die Eingabe\u00a0<code>0.5<\/code>, ist, dann sollte die Ausgabe\u00a0<code>15.24<\/code>\u00a0sein.<br \/>\n<div class=\"helpOuter\" style=\"display: none;\"><div class=\"helpInner\"><div style=\"text-align: center\">You need to create an account and log in to ask a question.<\/div><\/div><\/div><div class='pyboxTextwrap pyboxCodewrap RW resizy'  style='height: 526px;'><textarea wrap='off' name='usercode15' id='usercode15'  cols=10 rows=20   class='pyboxCode RW'>\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory15' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput15\">You may enter input for the program in the box below.<div class=\"pyboxTextwrap resizy\" style=\"height: 102px;\" ><textarea wrap=\"off\" name=\"userinput\" class=\"pyboxInput\" cols=10 rows=4><\/textarea><\/div><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit15' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch15\" value=\"Input Switch\" onclick=\"pbInputSwitch(15,'N')\" ><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(15)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(15,'N')\" ><\/td>\n<\/tr><\/table><select id='pbSelect15' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(15,'7b.convert')\" >History<\/option>\n<option name='help' data-pbonclick=\"helpClick(15);\" >Help<\/option>\n<\/select><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse15\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"15\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"2c639b3a00c82eb1f806a1ee5784c013\"\/>\n<div id='pbresults15' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(15);});pbInputSwitch(15,\"N\");<\/script>\n<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform16\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox16'>\n<img title='You have not yet completed this problem.' src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/icon.png' class='pycheck'\/><div class=\"heading\"><span class='type'>Coding Exercise: <\/span><span class='title'>Erdanziehungskraft<\/span><\/div>Ein P\u00e4ckchen wird mit einer Geschwindigkeit von <em>v<\/em> m\/s und bei einer H\u00f6he von 11.000 m aus einem Flugzeug geworfen. W\u00e4hrend es f\u00e4llt, wird der Abstand zum Boden angegeben mit der Formel -4.9<em>t<\/em><sup>2<\/sup> - <em>vt<\/em> + 11000, wobei <em>t<\/em> die Zeit in Sekunden ist, seit es abgeworfen wurde. Schreibe ein Programm, das die Zeit ausgibt, die das P\u00e4ckchen braucht, um den Boden zu erreichen. Die Eingabe f\u00fcr dein Programm ist die positive Gleitpunktzahl <em>v.<\/em> Die ben\u00f6tigte Zeit wird mittels der folgenden quadratischem Formel angegeben:<\/p>\n<p style=\"text-align: center;\"><img src='https:\/\/s0.wp.com\/latex.php?latex=%5Cdisplaystyle%7Bt%3D%5Cfrac%7Bv-%5Csqrt%7Bv%5E2-4%28-4.9%29%2811000%29%7D%7D%7B2%28-4.9%29%7D%7D&#038;bg=T&#038;fg=000000&#038;s=2' alt='\\displaystyle{t=\\frac{v-\\sqrt{v^2-4(-4.9)(11000)}}{2(-4.9)}}' title='\\displaystyle{t=\\frac{v-\\sqrt{v^2-4(-4.9)(11000)}}{2(-4.9)}}' class='latex' \/><\/p>\n<p><div class=\"helpOuter\" style=\"display: none;\"><div class=\"helpInner\"><div style=\"text-align: center\">You need to create an account and log in to ask a question.<\/div><\/div><\/div><div class='pyboxTextwrap pyboxCodewrap RW resizy'  style='height: 526px;'><textarea wrap='off' name='usercode16' id='usercode16'  cols=10 rows=20   class='pyboxCode RW'>\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory16' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput16\">You may enter input for the program in the box below.<div class=\"pyboxTextwrap resizy\" style=\"height: 102px;\" ><textarea wrap=\"off\" name=\"userinput\" class=\"pyboxInput\" cols=10 rows=4><\/textarea><\/div><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit16' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch16\" value=\"Input Switch\" onclick=\"pbInputSwitch(16,'N')\" ><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(16)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(16,'N')\" ><\/td>\n<\/tr><\/table><select id='pbSelect16' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(16,'7b.gravity')\" >History<\/option>\n<option name='help' data-pbonclick=\"helpClick(16);\" >Help<\/option>\n<\/select><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse16\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"16\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"895f1fb203cf89ef9629cae02c00abd0\"\/>\n<div id='pbresults16' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(16);});pbInputSwitch(16,\"N\");<\/script>\n<\/p>\n<p>Gl\u00fcckwunsch! Nachdem du diese \u00dcbungen bew\u00e4ltigt hast, bist du bereit, dich anderen Lektionen zuzuwenden!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lektion 7 besteht aus drei Teilen A, B und C, die in beliebiger Reihenfolge bearbeitet werden k\u00f6nnen. Bislang haben wir mathematische Berechnungen angestellt, indem wir Pythons Operatoren +, -, *, \/ und die Funktionen max und min verwendet haben. In &hellip; <a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/7b-de\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2653,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5569","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5569","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/users\/2653"}],"replies":[{"embeddable":true,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/comments?post=5569"}],"version-history":[{"count":42,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5569\/revisions"}],"predecessor-version":[{"id":15824,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5569\/revisions\/15824"}],"wp:attachment":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/media?parent=5569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}