{"id":5575,"date":"2012-09-13T16:45:04","date_gmt":"2012-09-13T20:45:04","guid":{"rendered":"http:\/\/cscircles.cemc.uwaterloo.ca\/?page_id=5575"},"modified":"2024-07-26T04:13:49","modified_gmt":"2024-07-26T08:13:49","slug":"9-de","status":"publish","type":"page","link":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/9-de\/","title":{"rendered":"9: F\u00e4lle &#038; Logik"},"content":{"rendered":"<p>Diese Lektion wird es dir erm\u00f6glichen, das komplexe \u00dcberpr\u00fcfen von F\u00e4llen wesentlich eleganter zu machen, wobei du nur zwei neue Teile der Python-Sprache verwendest.<\/p>\n<ul>\n<li>nach einem <code>if \u00abC\u00bb<\/code> Statement wird ein <code>else<\/code> Statement nur ausgef\u00fchrt, wenn <code>C<\/code> <em>false<\/em> ist<\/li>\n<li>Du kannst Boolesche Bedingungen kombinieren, indem du <code>A and B<\/code>, <code>A or B<\/code>, und <code>not A<\/code> verwendest<\/li>\n<\/ul>\n<h1><code>else<\/code><\/h1>\n<p>Eine sehr \u00fcbliche Aufgabe beim Schreiben von Programmen ist es, dass du einige Bedingungen \u00fcberpr\u00fcfen m\u00f6chtest, und entweder eine bestimmte Handlung ausf\u00fchren m\u00f6chtest oder eine andere, abh\u00e4ngig davon, ob die Bedingung wahr ist oder falsch. <a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/6-de\/\">Fr\u00fcher<\/a> verlangte eine \u00dcbung etwas zu tun, falls <code>age<\/code> kleiner als 0 war,<br \/>\netwas anderes, wenn <code>age<\/code> nicht kleiner als 0 war; der Code war etwa<\/p>\n<pre>if age &gt;= 0:  \n  print('Du bist nicht unbedingt ein Zeitreisender')\nif age &lt; 0:\n  print('Du bist ein Zeitreisender')<\/pre>Jetzt schreiben wir es neu und verwenden <code>else<\/code>:<\/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=\"title\">Example<\/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'>\nage = int(input())\nif age &gt;= 0:\n  print('Du bist nicht unbedingt ein Zeitreisender')\nelse: # instead of a second 'if'!\n  print('Du bist ein Zeitreisender')<\/textarea><\/div>\n<div id='pbhistory0' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput0\">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='submit0' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch0\" value=\"Input Switch\" onclick=\"pbInputSwitch(0,'N')\" ><\/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=\"d8f51ac2c16a0a17494c9ca3835c9519\"\/>\n<div id='pbresults0' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>pbInputSwitch(0,\"N\");<\/script>\n<\/p>\n<p>Allgemeiner kannst du auch <code>else<\/code> mit dem folgenden Paar von Block Statements verwenden:<\/p>\n<pre>if \u00abtest\u00bb:\n   \u00abtrue-body\u00bb        # an indented block\nelse:\n   \u00abfalse-body\u00bb       # another indented block<\/pre>Python beurteilt den Test. Wenn er wahr ist, dann wird der True-K\u00f6rper ausgef\u00fchrt, und wenn er falsch ist, wird der False-Body ausgef\u00fchrt.<\/p>\n<h2>Die Philosophie von <code>else<\/code><\/h2>\n<p>Wir erhalten keine neuen F\u00e4higkeiten durch <code>else<\/code>, aber es macht Code viel leichter zu lesen, debuggen und zu pflegen. Hier sind zwei Codefragmente, die das gleiche machen.<\/p>\n<table id=\"AB\">\n<tbody>\n<tr>\n<td>\n<div>Version A<\/div>\n<pre>if height &lt; 256:\n   print('Too short for this ride')\nelse:\n   print('Welcome aboard!')<\/pre>\n<\/td>\n<td>\n<div>Version B<\/div>\n<pre>if height &lt; 256:\n   print('Too short for this ride')\nif height &gt;= 256:\n   print('Welcome aboard!')<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Beide machen das gleiche, und <strong>B<\/strong> braucht nicht einmal <code>else<\/code>. Die meisten Programmierer w\u00fcrden allerdings einig dar\u00fcber sein, dass <strong>A<\/strong> besser ist. So ist es zum Beispiel bei <strong>A<\/strong> so, dass das \u00c4ndern einer Bedingung (z.B. 128 zu verwenden anstatt von 256) nur eine \u00c4nderung des Codes ben\u00f6tigt anstatt zwei. Au\u00dferdem kann <strong>A<\/strong> sofort verstanden werden von einem menschlichen Leser, im Gegensatz zu <strong>B<\/strong>, das darauf \u00fcberpr\u00fcft werden muss, ob beide oder keine der Bedingungen wahr sein k\u00f6nnen.<\/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'>Absoluter Wert<\/span><\/div>Der <em>absolute Wert <\/em>einer Zahl wird folgenderma\u00dfen definiert: f\u00fcr eine Zahl <em>x,<\/em> die positiv oder null ist, ist der absolute Wert von <em>x<\/em> genau <em>x<\/em>. Wenn x hingegen eine negative Zahl ist, ist der absolute Wert von <em>x<\/em> gleich<em> -x<\/em>, in anderen Worten der gleiche wie <em>x<\/em> aber ohne das Minuszeichen. Zum Beispiel ist der absolute Wert von <code>5<\/code> gleich <code>5<\/code>, und der absolute Wert von <code>-10<\/code> ist <code>10<\/code>. Verwende <code>if<\/code> und <code>else<\/code>, um ein Programm zu schreiben, das eine ganze Zahl als Input nimmt und ihren absoluten Wert ausgibt.<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'>\nx=int(input())\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<input type='hidden' id='defaultCode1' value='x=int(input())\\n'><\/input>\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,'9.abs')\" >History<\/option>\n<option name='default' data-pbonclick=\"pbSetText(1,descape($('#defaultCode1').val()))\" >Reset code to default<\/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=\"17804b156331d382701ddebb92c9b9f5\"\/>\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> Python hat eine eingebaute Funktion <code>abs(x),<\/code> um den absoluten Wert von <code>x<\/code> zu berechnen. Die Auswertung der vorangegangenen \u00dcbung verhindert, dass du sie jetzt verwenden kannst, aber du wirst sie sp\u00e4ter verwenden k\u00f6nnen. <\/span><\/td><\/table><\/p>\n<h2><code>elif<\/code><\/h2>\n<p>Python f\u00fchrt ein weiteres Schl\u00fcsselwort ein, <code>elif<\/code>, um es einfacher zu machen, mehrere Bedingungen hintereinander zu checken. Die einfachste Form von <code>elif<\/code> ist die Folgende:<\/p>\n<pre>if \u00abtest1\u00bb:\n   \u00abbody1\u00bb        # runs if test1 is true\nelif \u00abtest2\u00bb:\n   \u00abbody2\u00bb        # runs if test1 is false and test2 is true<\/pre>Wie du vielleicht schon geraten hast, steht <code>elif<\/code> kurz f\u00fcr \"else if\", da es das gleiche ist, wie ein if Statement in einen else Block zu verpacken. Es f\u00fchrt allerdings zu k\u00fcrzerem Code und weniger einger\u00fcckten Zeilen, was dein Programm leichter zu lesen, debuggen und bearbeiten macht. Au\u00dferdem kannst du <em>eine beliebige Anzahl<\/em> von elif Statements am St\u00fcck kombinieren und sogar wahlweise ein <code>else<\/code> Statement ans Ende f\u00fcgen:<\/p>\n<pre>if \u00abtest1\u00bb:\n   \u00abbody1\u00bb      # runs if test1 is true\nelif \u00abtest2\u00bb:\n   \u00abbody2\u00bb      # runs if test1 is false and test2 is true\nelif \u00abtest3\u00bb:\n   \u00abbody3\u00bb      # runs if test1 &amp; test2 both false and test3 is true\nelse:         # these last two lines are optional\n   \u00abelse-body\u00bb  # runs if ALL the tests are false<\/pre>Hier ist ein Beispiel mit <code>elif<\/code>, welches innerhalb einer Schleife benutzt wird. Kannst du die Ausgabe voraussagen bevor sie l\u00e4uft?<\/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+x+in+range%281%2C+10%29%3A%0A+if+x+%25+2+%3D%3D+0%3A%0A++print%28x%2C+%27is+even%27%29%0A+elif+x+%25+3+%3D%3D+0%3A%0A++print%28x%2C+%27is+an+odd+multiple+of+3%27%29%0A+else%3A%0A++print%28x%2C+%27not+divisible+by+2+or+3%27%29&cumulative=false&heapPrimitives=false&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=3&curInstr=0&resizeContainer=true&highlightLines&width=450px&rightStdout=1'><\/iframe><\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform2\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox2'>\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'>First, Second, Third<\/span><\/div>Die englischen Worte 1st, 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, 9th (also 1stes, 2tes, 3tes etc.) nennt man <em>Numerale<\/em>. Schreibe ein Programm, das eine Ganzzahl <em>x<\/em> zwischen 1 und 9 aus dem Input liest. Das Programm sollte das zu <em>x<\/em> geh\u00f6rige Numeral ausgeben. <br\/> <strong>Tipp<\/strong>: Du ben\u00f6tigst keine 9 verschiedenen F\u00e4lle; 4 reichen v\u00f6llig 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='usercode2' id='usercode2'  cols=10 rows=20   class='pyboxCode RW'>\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory2' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput2\">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='submit2' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch2\" value=\"Input Switch\" onclick=\"pbInputSwitch(2,'N')\" ><\/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><select id='pbSelect2' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(2,'9.ordinal')\" >History<\/option>\n<option name='help' data-pbonclick=\"helpClick(2);\" >Help<\/option>\n<\/select><\/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=\"c4b3f10cc0deac89d5354ed7137f3680\"\/>\n<div id='pbresults2' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(2);});pbInputSwitch(2,\"N\");<\/script>\n<\/p>\n<h2>Boolesche Operatoren: <code>and<\/code>, <code>or<\/code>, <code>not<\/code><\/h2>\n<p>Du kannst Boolesche Ausdr\u00fccke kombinieren, indem du \"<code>and<\/code>\", \"<code>or<\/code>\", und \"<code>not<\/code>\" verwendest, die genauso funktionieren wie in normaler Sprache.<\/p>\n<ul>\n<li>Der Ausdruck <code>A and B<\/code> ist wahr, wenn sowohl <code>A<\/code> als auch <code>B<\/code> wahr sind, und falsch, wenn eines der beiden falsch ist. (Zum Beispiel wirst du nass, wenn es regnet <code>und<\/code> du deinen Schirm vergessen hast.)<\/li>\n<li>Der Ausdruck <code>A or B<\/code> ist wahr, wenn entweder <code>A<\/code> wahr ist, oder <code>B<\/code> wahr ist, und falsch, wenn beide falsch sind. (Zum Beispiel ist die Schule geschlossen, wenn es ein gesetzlicher Feiertag ist <code>oder<\/code> wenn es ein Wochenende ist.)<\/li>\n<li>Der Ausdruck <code>not A<\/code> ist wahr, wenn <code>A<\/code> falsch ist, und falsch, wenn <code>A<\/code> wahr ist. (Zum Beispiel bist du hungrig, wenn du <code>nicht<\/code> Mittagessen hattest.)<\/li>\n<\/ul>\n<p>Hier ist ein Programm, das automatisch alle M\u00f6glichkeiten darstellt. Genau wie die 'Multiplikationstabellen', an die du dich noch aus der Grundschulzeit erinnerst, nennt man dies eine <em>Wahrheitstabelle<\/em>.<\/p>\n<p><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>Wahrheitstabellen<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 136px;'><textarea wrap='off' name='usercode3' id='usercode3'  cols=10 rows=5 readonly='readonly'  style = 'height : 136px;'  class='pyboxCode RO'>\nprint(\"  A      B       not A  not B  A and B  A or B\")\nprint(\"----------------------------------------------\")\nfor A in [False, True]:               # \"for\" loop with list\t\n    for B in [False, True]:           # will be taught in lesson 13\n        print(A, \" \", B, \"   \", not A, \" \", not B, \" \", A and B, \" \", A or B)<\/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=\"23fac91eb493ba893eb781d9128bd39c\"\/>\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<\/p>\n<p>Als ein Beispiel der Verwendung von <code>and<\/code> ist hier ein Programm, das Zahlen zu Buchstaben umwandelt, mit einer Fehler\u00fcberpr\u00fcfung.<br \/>\n<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 Beispiel von <code>and<\/code>: Zahlen zu Buchstaben umwandeln, mit 1=A, 2=B, etc.<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'>\nx = int(input())\nif x>=1 and x<=26:\n    print('letter', x, 'in the alphabet:', chr(ord('A')+(x-1)))\nelse:\n    print('invalid input:', x)<\/textarea><\/div>\n<div id='pbhistory4' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput4\">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='submit4' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch4\" value=\"Input Switch\" onclick=\"pbInputSwitch(4,'N')\" ><\/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=\"4b610da4b77d47e08a914c94baf24596\"\/>\n<div id='pbresults4' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>pbInputSwitch(4,\"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'>26 Letters<\/span><\/div>Schreibe ein Programm, welches das Gegenteil des obigen Beispiels ausf\u00fchrt: es sollte ein Zeichen als Input nehmen und die dazugeh\u00f6rige Zahl (zwischen 1 und 26) ausgeben. Dein Programm sollte nur <em>Gro\u00dfbuchstaben<\/em> annehmen. Zur Fehler\u00fcberpr\u00fcfung, gib <code>invalid<\/code> aus, wenn die Eingabe kein Gro\u00dfbuchstabe ist. <a class=\"hintlink\"  id=\"hintlink6\">Tipp<\/a><a class=\"hintlink\"  id=\"hintlink7\">Alternative Methode zum Vergleich von Zeichenketten<\/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'>\nletter = 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='letter = 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,'9.numberify')\" >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=\"914bc16d897335d6f081eab91eae9621\"\/>\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<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'>Multiple Choice Exercise: <\/span><span class='title'>De Morgansche Gesetze<\/span><\/div><div>Welche der folgenden Ausdr\u00fccke ist gleich <code>A or B<\/code>?<\/div><label>Your choice: <\/label><select id=\"pyselect8\"><option value=\"d\" selected>Select one<\/option><option value=\"w\">not (A and B)<\/option><option value=\"w\">(not A) and (not B)<\/option><option value=\"r\">not ((not A) and (not B))<\/option><\/select><div class='pyboxbuttons'><input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" name=\"slug\" value=\"9.demorgan\"\/><input type='submit' style='margin:5px;' value='Check answer' onClick='pbMultiCheck(8)'\/><\/div><div class=\"pbresults\" id=\"pyMultiResults8\"><\/div><div class=\"epilogue\">Korrekt! Hier ist zum Beispiel eine m\u00f6gliche Herleitung f\u00fcr diese L\u00f6sung. Zuerst stellen wir fest, dass <code>not (A or B)<\/code> nur dann wahr ist, wenn sowohl <code>A<\/code> und <code>B<\/code> falsch sind. Also, beachten wir, dass <code>(not A) and (not B)<\/code> nur dann wahr ist, wenn sowohl <code>not A<\/code> als auch <code>not B<\/code> wahr sind, d.h. wenn sowohl <code>A<\/code> als auch <code>B<\/code> falsch sind. Dies ergibt die folgenden Gleichungen:\n<pre>(not A) and (not B) = not (A or B)<\/pre>\nWenn wir ein <code>not<\/code> an beide Seiten anlegen, schlie\u00dfen wir\n<pre>not ((not A) and (not B)) = not (not (A or B))<\/pre>\nund beobachten, dass <code>not(not X))<\/code> immer gleich <code>X<\/code> ist, sodass\n<pre>not ((not A) and (not B)) = not (not (A or B)) = A or B<\/pre>\nDiese Art und Weise, einen Booleschen Ausdruck umzuschreiben ist eins der De Morganschen Gesetze.<\/div><\/div>\n<h3>Operatorrangfolge<\/h3>\n<p><span style=\"color: #444444; line-height: 24px;\">Boolesche Operatoren haben genauso eine <a href=\"http:\/\/de.wikipedia.org\/wiki\/Operatorrangfolge\">Operatorrangfolge<\/a> wie mathematische Operatoren. Diese Reihenfolge ist<\/span><\/p>\n<p style=\"text-align: center;\"><strong>NAO<\/strong>: not (h\u00f6chste Rangordnung), and, or (niedrigste Rangordnung)<\/p>\n<p style=\"text-align: left;\">so bedeutet zum Beispiel<\/p>\n<p style=\"text-align: center;\"><code>not x or y and z<\/code> folgendes: <code>(not x) or (y and z)<\/code><\/p>\n<p>Wir schlie\u00dfen diese Lektion mit einer kurzen Frage ab, f\u00fcr die wir diese Fakten verwenden.<br \/>\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'>Multiple Choice Exercise: <\/span><span class='title'>Operatorrangfolge<\/span><\/div><div>Was ist der Wert von<\/p>\n<pre>A or not B and C<\/pre>wenn (A, B, C) = (False, True, True)? <a class=\"hintlink\"  id=\"hintlink10\">Tipp<\/a><\/div><label>Your choice: <\/label><select id=\"pyselect9\"><option value=\"d\" selected>Select one<\/option><option value=\"w\">True<\/option><option value=\"r\">False<\/option><\/select><div class='pyboxbuttons'><input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" name=\"slug\" value=\"9.multi\"\/><input type='submit' style='margin:5px;' value='Check answer' onClick='pbMultiCheck(9)'\/><\/div><div class=\"pbresults\" id=\"pyMultiResults9\"><\/div><div class=\"epilogue\">Korrekt! Die Operatorrangfolge macht dies gleichwertig zu\n<pre>A or ((not B) and C)<\/pre>\nwenn wir die Werte austauschen, haben wir\n<pre>False or ((not True) and True)<\/pre>\nund wenn wir jetzt auch noch Schritt f\u00fcr Schritt vereinfachen, haben wir am Ende\n<pre>False or ((not True) and True)\n= False or (False and True)\n= False or False\n= False<\/pre>\n<\/div><\/div>Wenn du diese Aufgabe geschafft hast, bist du bereit f\u00fcr die n\u00e4chste Lektion!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Diese Lektion wird es dir erm\u00f6glichen, das komplexe \u00dcberpr\u00fcfen von F\u00e4llen wesentlich eleganter zu machen, wobei du nur zwei neue Teile der Python-Sprache verwendest. nach einem if \u00abC\u00bb Statement wird ein else Statement nur ausgef\u00fchrt, wenn C false ist Du &hellip; <a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/9-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-5575","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5575","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=5575"}],"version-history":[{"count":51,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5575\/revisions"}],"predecessor-version":[{"id":15956,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5575\/revisions\/15956"}],"wp:attachment":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/media?parent=5575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}