{"id":5571,"date":"2012-09-13T16:43:26","date_gmt":"2012-09-13T20:43:26","guid":{"rendered":"http:\/\/cscircles.cemc.uwaterloo.ca\/?page_id=5571"},"modified":"2020-04-08T08:43:24","modified_gmt":"2020-04-08T12:43:24","slug":"7c-de","status":"publish","type":"page","link":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/7c-de\/","title":{"rendered":"7C: Schleifen"},"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>Bis jetzt haben wir grundlegende Programmierbefehle erlernt (z.B. das Zuweisen von Werten, das Ausgeben von Werten), ebenso wie <code>if<\/code> Befehle. In dieser Lektion f\u00fchren wir <strong>Schleifen<\/strong> ein (manchmal auch <strong>Wiederholungen<\/strong> oder <strong>Iterationen<\/strong> genannt: eine M\u00f6glichkeit, den Computer immer wieder die gleiche Sache (oder \u00e4hnliche Dinge) machen zu lassen. Zum Beispiel w\u00fcrde die Rechtschreibpr\u00fcfung <em>jedes<\/em> Wortes in einem Dokument mit einer Schleife gemacht werden. Wir werden in dieser Lektion die beiden Arten von Python Schleifen beschreiben: <code>while<\/code> Schleifen und <code>for<\/code> Schleifen.<\/p>\n<h2><code>while<\/code> Schleifen<\/h2>\n<p>Ein <code>while<\/code>-Statement (also ein \u201eW\u00e4hrend\u201c-Statement) wiederholt einen Code-Abschnitt immer wieder, solange bestimmte Bedingungen noch erf\u00fcllt sind. Hier ist ein Beispiel:<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform0\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox0'>\n<div class=\"heading\"><span class='type'>Example: <\/span><span class='title'>Countdown<\/span><\/div> <div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 136px;'><textarea wrap='off' name='usercode0' id='usercode0'  cols=10 rows=5 readonly='readonly'  style = 'height : 136px;'  class='pyboxCode RO'>\ntimeLeft = 5\nwhile timeLeft &gt; 0:           # condition\n  print(timeLeft)             # body\n  timeLeft = timeLeft-1       # body\nprint('Blastoff!')            # this is not part of the loop<\/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=\"03a969fd1b93343591cf5b522cf9c420\"\/>\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>Hier ist die allgemeine Struktur:<\/p>\n<ul>\n<li>Die erste Zeile ist die <code>w\u00e4hrend - \u00abBedingung\u00bb:<\/code>, wobei wir 'Bedingung' solche Ausdr\u00fccke nennen, die <code>Wahr<\/code> or <code>Falsch<\/code> ausgeben (so wie ein <code>if<\/code> Statement)<\/li>\n<li>Danach setzen wir einen einger\u00fcckten Textblock (wieder so wie ein <code>if<\/code> Statement), der aus den Statements besteht, die wir immer wieder wiederholt sehen m\u00f6chten. Dies nennt man den <em>K\u00f6rper<\/em>.<\/li>\n<li>Wenn du das Programm ausf\u00fchrst, wird das Folgende wiederholt:\n<ul>\n<li>Die Bedingung wird \u00fcberpr\u00fcft; wenn die Bedingung <code>Wahr<\/code> ist, wird der K\u00f6rper ausgef\u00fchrt und im Anschluss wiederholen wir von vorne. Erst wenn die Bedingung als <code>Falsch<\/code> beurteilt wird, endet diese Schleife.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\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'>Countup<\/span><\/div>Ver\u00e4ndere das obige Beispiel um ein Programm zu schreiben, wo wir von 1 <strong>aufsteigend<\/strong> z\u00e4hlen bis <strong>10<\/strong>, und dann geben wir das Wort <code>Blastoff!<\/code> aus.<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,'7c.countup')\" >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=\"47ecfba3447f586a963a2b52e6a4e207\"\/>\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><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> Mit Schleifen ist es einfach ein Programm zu schreiben, das ewig in einem <em>unendlichen Kreislauf<\/em> l\u00e4uft. <form class=\"pbform\" action=\"#\" id=\"pbform2\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox2'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>Unendliche Schleife<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 58px;'><textarea wrap='off' name='usercode2' id='usercode2'  cols=10 rows=2 readonly='readonly'  style = 'height : 58px;'  class='pyboxCode RO'>\nwhile True:\n  x=1<\/textarea><\/div>\n<div id='pbhistory2' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit2' value=' '\/><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(2)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(2,'N')\" ><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse2\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"2\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"560c1de6c15792f92161578204f2ecb2\"\/>\n<div id='pbresults2' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit2\").value = \"Run program\";document.getElementById(\"inputInUse2\").value = \"N\";<\/script>\n Man bekommt die Fehlermeldung \"Time Limit Exceeded\" weil der CS Circles webserver ein Zeitlimit erzwingt. Nach 1 Sekunde wird das Programm beendet. Wenn du <a href=\"\/run-at-home\/\">das Programm zuhause durchgef\u00fchrt h\u00e4ttest<\/a>, w\u00fcrde es ewig laufen (bis du es selbst beendet h\u00e4ttest, \u00fcblich durch das Dr\u00fccken von Strg-C). <\/span><\/td><\/table><\/p>\n<h2><code>for<\/code> Schleifen<\/h2>\n<p>Es gibt noch eine andere Art von Schleifen in Python, die man eine <code>f\u00fcr<\/code>-Schleife nennt. In vielen Situationen k\u00f6nnen beide Arten von Schleifen (<code>f\u00fcr<\/code>\/<code>w\u00e4hrend<\/code>) verwendet werden, aber eine ist einfacher als die andere, also ist es hilfreich zu wissen, wie man beide verwendet. Eine <code>for<\/code>-Schleife wird gebaut, um eine Reihe von Zahlen (oder wie wir sp\u00e4ter sehen werden, irgendeine Liste von Daten) systematisch durchzugehen.<\/p>\n<p>Hier ist ein Beispiel einer <code>for<\/code>-Schleife.<\/p>\n<p><iframe width='100%' height='480' frameborder='0' scrolling='no' src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/OnlinePythonTutor3-cemc\/iframe-embed.html#code=for+counter+in+range%2810%2C+15%29%3A%0A++print%28%22The+counter%27s+value+is%22%2C+counter%29&cumulative=false&heapPrimitives=false&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=3&curInstr=0&resizeContainer=true&highlightLines&width=400&rightStdout=1'><\/iframe><\/p>\n<p>Die allgemeine Struktur einer numerischen <code>for<\/code>-Schleife ist<\/p>\n<pre>for \u00abvariableName\u00bb in range(\u00abstartValue\u00bb, \u00abtailValue\u00bb):\r\n  \u00abindented block of commands, called the loop \"body\"\u00bb<\/pre>Wie immer kann der K\u00f6rper mehrere Zeilen lang sein, solange alle Zeilen im selben Ma\u00df einger\u00fcckt sind. Zuerst wird der K\u00f6rper der Schleife ausgef\u00fchrt mit <code>variableName<\/code> der auf <code>startValue<\/code> eingestellt wird. Dann wird das Ganze wiederholt mit <code>variableName<\/code> eingestellt auf <code>startValue+1<\/code>, dann auf <code>startValue+2<\/code>, etc. Das wird nun fortgef\u00fchrt bis <code>variableName<\/code> den Wert <code>tailValue-1<\/code> hat, woraufhin die Schleife beendet ist.<\/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> Die Schleife h\u00f6rt mit <code>tailValue-1<\/code> auf und nicht mit <code>tailValue<\/code>!<form class=\"pbform\" action=\"#\" id=\"pbform3\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox3'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div> <div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 58px;'><textarea wrap='off' name='usercode3' id='usercode3'  cols=10 rows=2 readonly='readonly'  style = 'height : 58px;'  class='pyboxCode RO'>\nfor i in range(1, 3):\n print(i)  # 3 is not printed!<\/textarea><\/div>\n<div id='pbhistory3' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit3' value=' '\/><\/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><\/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=\"3a914e14c11a84c2cdee1689016bff6b\"\/>\n<div id='pbresults3' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit3\").value = \"Run program\";document.getElementById(\"inputInUse3\").value = \"N\";<\/script>\n <\/span><\/td><\/table><\/p>\n<p>Hier ist ein Beispiel einer <code>for<\/code>-Schleife in einer anderen <code>for<\/code>-Schleife.<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform4\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox4'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>Ein 5x5 Quadrat ausgeben. <br\/><strong>Achtung<\/strong>: <code>S = S + '*'<\/code> stellt ein <code>*<\/code> Zeichen ans Ende der Kette <code>S<\/code> (wie wir das in Lektion 7A gelernt haben).<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 136px;'><textarea wrap='off' name='usercode4' id='usercode4'  cols=10 rows=5 readonly='readonly'  style = 'height : 136px;'  class='pyboxCode RO'>\nfor i in range(0, 5):\n  S = ''\n  for j in range(0, 5):\n    S = S + '*'\n  print(S)<\/textarea><\/div>\n<div id='pbhistory4' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit4' value=' '\/><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(4)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(4,'N')\" ><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse4\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"4\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"391d1f0929b57d24c74b42c647263de5\"\/>\n<div id='pbresults4' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit4\").value = \"Run program\";document.getElementById(\"inputInUse4\").value = \"N\";<\/script>\n<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform5\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox5'>\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'>One Triangle<\/span><\/div>Ver\u00e4ndere das vorangegangene Programm auf zwei Arten: Zuerst, anstatt eines Quadrats, lass es ein Dreieck zeichnen, das folgenderma\u00dfen geformt ist: \u25e4. Zweitens, anstatt immer f\u00fcnf Zeilen zu haben, sollte die gew\u00fcnschte Gr\u00f6\u00dfe eingegeben werden. Zum Beispiel, wenn die Eingabe <code>3<\/code> ist, sollte die Ausgabe so aussehen:<\/p>\n<pre>111\r\n11\r\n1<\/pre><a class=\"hintlink\"  id=\"hintlink6\">Klicke hier f\u00fcr einen 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='usercode5' id='usercode5'  cols=10 rows=20   class='pyboxCode RW'>\nn=int(input())\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory5' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput5\">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<input type='hidden' id='defaultCode5' value='n=int(input())\\n'><\/input>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit5' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch5\" value=\"Input Switch\" onclick=\"pbInputSwitch(5,'N')\" ><\/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><select id='pbSelect5' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(5,'7c.triangle')\" >History<\/option>\n<option name='default' data-pbonclick=\"pbSetText(5,descape($('#defaultCode5').val()))\" >Reset code to default<\/option>\n<option name='help' data-pbonclick=\"helpClick(5);\" >Help<\/option>\n<\/select><\/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=\"6876e6ab561ddb4bb4175cf01346e381\"\/>\n<div id='pbresults5' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(5);});pbInputSwitch(5,\"N\");<\/script>\n<\/p>\n<h2>Die <code>break<\/code> und <code>continue<\/code> Statements<\/h2>\n<p>Das <code>break<\/code> (Bruch oder Abbruch) Statement ist wie ein Notausgang f\u00fcr eine <code>while<\/code> oder <code>for<\/code> Schleife: <code>break<\/code> sorgt f\u00fcr einen sofortigen Sprung zu den Befehlen nach dem Ende des Schleifenk\u00f6rpers. Hier ist ein Beispiel f\u00fcr die Verwendung von <code>break<\/code>: das Programm liest alle Inputzeilen bis es eine findet, die besagt <code>\"END\"<\/code>.<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform7\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox7'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>Durch alle eingegebenen Zeilen schleifen<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 188px;'><textarea wrap='off' name='usercode7' id='usercode7'  cols=10 rows=7 readonly='readonly'  style = 'height : 188px;'  class='pyboxCode RO'>\ncounter = 0\nwhile True:\n  lineIn = input()\n  if lineIn == 'END':\n    break\n  counter = counter+1\n  print('line', counter, '=', lineIn)<\/textarea><\/div>\n<div id='pbhistory7' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit7' value=' '\/><\/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><\/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=\"81a9e3510f5e28d6521c90a9167dff6a\"\/>\n<div id='pbresults7' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit7\").value = \"Run program\";document.getElementById(\"inputInUse7\").value = \"N\";<\/script>\n<\/p>\n<p>Das <code>continue<\/code> Statement sorgt daf\u00fcr, dass du den Rest einer Schleife <strong>\u00fcberspringst<\/strong>, um dann den K\u00f6rper aus der n\u00e4chsten Runde zu wiederholen (\u00fcblicherweise die n\u00e4chste \"Iteration\" genannt).<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform8\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox8'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div><div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 110px;'><textarea wrap='off' name='usercode8' id='usercode8'  cols=10 rows=4 readonly='readonly'  style = 'height : 110px;'  class='pyboxCode RO'>\nfor n in range(10, 16):\n  if (n == 13):  # bad luck\n    continue     # so we skip it\n  print(n)<\/textarea><\/div>\n<div id='pbhistory8' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit8' value=' '\/><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(8)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(8,'N')\" ><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse8\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"8\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"5ebbb36b223189ee0024ccf814fd8343\"\/>\n<div id='pbresults8' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit8\").value = \"Run program\";document.getElementById(\"inputInUse8\").value = \"N\";<\/script>\n<\/p>\n<h2>\u00dcbungen<\/h2>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform9\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox9'>\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'>Square Census<\/span><\/div>Die quadrierten Zahlen sind ganze Zahlen der Form K * K, z.B. ist 9 eine quadrierte Zahl da 3 * 3 = 9. Schreibe ein Programm, das eine ganze Zahl <em>n<\/em> aus dem Input liest und alle positiven Quadrate, die kleiner sind als <em>n<\/em> ausgibt, und zwar eins pro Zeile, in aufsteigender Reihenfolge. Wenn zum Beispiel die Eingabe 16 ist, w\u00e4re die korrekte Ausgabe<\/p>\n<pre>1\r\n4\r\n9<\/pre><a class=\"hintlink\"  id=\"hintlink10\">Tipp<\/a><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='usercode9' id='usercode9'  cols=10 rows=20   class='pyboxCode RW'>\nn=int(input())\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory9' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput9\">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<input type='hidden' id='defaultCode9' value='n=int(input())\\n'><\/input>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit9' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch9\" value=\"Input Switch\" onclick=\"pbInputSwitch(9,'N')\" ><\/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><select id='pbSelect9' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(9,'7c.squares')\" >History<\/option>\n<option name='default' data-pbonclick=\"pbSetText(9,descape($('#defaultCode9').val()))\" >Reset code to default<\/option>\n<option name='help' data-pbonclick=\"helpClick(9);\" >Help<\/option>\n<\/select><\/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=\"2d531794dfbb131558c4d9158e699e01\"\/>\n<div id='pbresults9' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(9);});pbInputSwitch(9,\"N\");<\/script>\n<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform11\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox11'>\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'>Skipping<\/span><\/div>Weite das \"Lege eine Schleife durch alle Inputzeilen\" - Beispiel oben (wir haben es nochmal f\u00fcr dich kopiert) aus, indem du eine neue Eigenschaft hinzuf\u00fcgst. Jede Zeile, die gleich <code>SKIP<\/code> ist, also dem \u00dcbersprungscode, soll nicht ausgegeben werden und sollte den Z\u00e4hler nicht erh\u00f6hen. Lasse das Programm einmal durchlaufen, um ein Beispiel zu sehen. <a class=\"hintlink\"  id=\"hintlink12\">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='usercode11' id='usercode11'  cols=10 rows=20   class='pyboxCode RW'>\ncounter = 0\nwhile True:\n  lineIn = input()\n  if lineIn=='END':\n    break\n  counter = counter+1\n  print('line', counter, '=', lineIn)\n<\/textarea><\/div>\n<div id='pbhistory11' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput11\">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<input type='hidden' id='defaultCode11' value='counter = 0\\nwhile True:\\n  lineIn = input()\\n  if lineIn==\\u0027END\\u0027:\\n    break\\n  counter = counter+1\\n  print(\\u0027line\\u0027, counter, \\u0027=\\u0027, lineIn)\\n'><\/input>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit11' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch11\" value=\"Input Switch\" onclick=\"pbInputSwitch(11,'N')\" ><\/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><select id='pbSelect11' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(11,'7c.skip')\" >History<\/option>\n<option name='default' data-pbonclick=\"pbSetText(11,descape($('#defaultCode11').val()))\" >Reset code to default<\/option>\n<option name='help' data-pbonclick=\"helpClick(11);\" >Help<\/option>\n<\/select><\/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=\"72e252debdf7bde5e95b8768ecbf53ed\"\/>\n<div id='pbresults11' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(11);});pbInputSwitch(11,\"N\");<\/script>\n<\/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'>Faktoren finden<\/span><\/div>Wenn <em>a<\/em> * <em>b<\/em> = <em>n<\/em>, nennen wir <em>a<\/em> * <em>b<\/em> eine <strong>Faktorisierung<\/strong> von <em>n<\/em>. Schreibe bitte ein Programm, das eine positive ganze Zahl <em>n<\/em> als Eingabe nimmt, und dann alle Faktorisierungen von <em>n<\/em> ausgibt. Du solltest dabei der Formatierung folgen, die im folgenden Beispiel f\u00fcr <em>n<\/em>=10 gegeben wird.<\/p>\n<pre>1 times 10 equals 10\r\n2 times 5 equals 10\r\n5 times 2 equals 10\r\n10 times 1 equals 10<\/pre><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'>\nn = int(input())\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<input type='hidden' id='defaultCode13' value='n = int(input())\\n'><\/input>\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,'7c.factorize')\" >History<\/option>\n<option name='default' data-pbonclick=\"pbSetText(13,descape($('#defaultCode13').val()))\" >Reset code to default<\/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=\"a619ff3e738856669b4bccd4cc622407\"\/>\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","protected":false},"excerpt":{"rendered":"<p>Lektion 7 besteht aus drei Teilen A, B und C, die in beliebiger Reihenfolge bearbeitet werden k\u00f6nnen. Bis jetzt haben wir grundlegende Programmierbefehle erlernt (z.B. das Zuweisen von Werten, das Ausgeben von Werten), ebenso wie if Befehle. In dieser Lektion &hellip; <a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/7c-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-5571","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5571","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=5571"}],"version-history":[{"count":25,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5571\/revisions"}],"predecessor-version":[{"id":9009,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5571\/revisions\/9009"}],"wp:attachment":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/media?parent=5571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}