{"id":5563,"date":"2012-09-13T16:35:34","date_gmt":"2012-09-13T20:35:34","guid":{"rendered":"http:\/\/cscircles.cemc.uwaterloo.ca\/?page_id=5563"},"modified":"2024-05-23T03:31:43","modified_gmt":"2024-05-23T07:31:43","slug":"7a-de","status":"publish","type":"page","link":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/7a-de\/","title":{"rendered":"7A:  Zeichenketten bzw. Strings"},"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 Zeichenketten bzw. Strings (Elemente vom Typ <code>str<\/code> ) nur auf ganz einfache Art und Weise verwendet. In dieser Lektion zeigen wir, wie man Strings manipulieren kann: wie man sie auseinander nehmen kann, wie man sie kombinieren kann und wie man die unterschiedlichen <em>Zeichen<\/em> betrachten kann, aus denen ein String besteht.<\/p>\n<h2>Was ist ein String?<\/h2>\n<p>Alle Daten, die auf einem Computer gespeichert sind, werden letztlich als eine Folge von 0-en und 1-en gespeichert. Dazu geh\u00f6ren Texte, digitale B\u00fccher, Bilder, Lieder, Videos und \"executable files\", also ausf\u00fchrbare Dateien wie Spiele und Anwendungen. Textdaten werden in der Regel als Strings gespeichert:<\/p>\n<ul>\n<li>Ein String ist eine Kette (auch: Folge) von Zeichen. Der String \"Hello, World!\" z.B. enth\u00e4lt 13 Zeichen, darunter Buchstaben wie \"H\", \"e\" und Zeichensetzung wie \" \", \"!\".<\/li>\n<li>Jedes Zeichen im String entspricht genau genommen einer Zahl. Die Zahl ist der Code des Zeichens; \"H\" zum Beispiel entspricht der Zahl 72 (bzw. 48 im Hexadezimalsystem), und zwar sowohl im <a href=\"https:\/\/de.wikipedia.org\/wiki\/American_Standard_Code_for_Information_Interchange\">ASCII-Code<\/a> als auch im <a href=\"https:\/\/de.wikipedia.org\/wiki\/Unicode\">Unicode<\/a>.)<\/li>\n<\/ul>\n<p>(Zahlen werden vom Computer in einem <a href=\"https:\/\/de.wikipedia.org\/wiki\/Dualsystem\">bin\u00e4ren Format<\/a> gespeichert - eben als Folge von 0-en und 1-en, auch Bitfolge genannt. F\u00fcr ein Zeichen wird letztlich die bin\u00e4re Darstellung seines Zahlencodes gespeichert; f\u00fcr das \"H\" also die Bitfolge 01001000.)<\/p>\n<h2>Das Manipulieren von Strings als Folgen von Zeichen: <code>S[]<\/code><\/h2>\n<p>Um einen String zu manipulieren, m\u00fcssen wir in der Lage sein, auf die individuellen Zeichen zugreifen zu k\u00f6nnen, aus denen der String besteht. In Python wird dies folgenderma\u00dfen gemacht: f\u00fcr einen String <code>S<\/code> und eine Ganzzahl <code>index<\/code>, liefert die Notation<\/p>\n<pre>S[index]<\/pre>das Zeichen von <code>S<\/code> an der Position <code>index<\/code>. <strong>Nach der Konvention<\/strong> beginnt der String beim Index 0: also ist <code>S[0]<\/code> das erste Zeichen, <code>S[1]<\/code> das zweite Zeichen, etc. In \"Hello, World!\" ist die Liste von Zeichen (engl.: character) folgende:<\/p>\n<pre>Index: 0  1  2  3  4  5  6  7  8  9 10 11 12\nChar.: H  e  l  l  o  ,     W  o  r  l  d  !<\/pre>Beachte, dass das Zeichen an der Stelle Index 6 ein Leerzeichen 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> In vielen anderen Programmiersprachen gibt es eine besondere Kategorie f\u00fcr Zeichen. In Python sind Zeichen das gleiche wie Strings mit L\u00e4nge 1, also <a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/console\/?consolecode=ch%20%3D%20%22Hi%22%5B0%5D%0Aprint%28ch%29%0Aprint%28type%28ch%29%29%0Aprint%28len%28ch%29%29\" target=\"_blank\">ist ihr Typ <code>str<\/code><\/a>. <\/span><\/td><\/table><\/p>\n<h2>Die Anzahl von Zeichen in einem String finden: <code>len<\/code><\/h2>\n<p>Um die Anzahl von Zeichen in einem String zu finden, benutzen wir die Python Funktion <code>len<\/code>. Zum Beispiel ist <code>len(\"Hello, World!\")<\/code> gleich 13.<\/p>\n<div class='pybox modeNeutral' id='pybox0'>\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'>Das letzte Zeichen<\/span><\/div><div>Welchen Ausdruck kann man verwenden, um das <strong>letzte<\/strong> Zeichen in einem String <code>S<\/code> zu erhalten?<\/div><label>Your choice: <\/label><select id=\"pyselect0\"><option value=\"d\" selected>Select one<\/option><option value=\"w\">S[len(S)+1]<\/option><option value=\"r\">S[len(S)-1]<\/option><option value=\"w\">S[len(S)]<\/option><\/select><div class='pyboxbuttons'><input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" name=\"slug\" value=\"7a.last\"\/><input type='submit' style='margin:5px;' value='Check answer' onClick='pbMultiCheck(0)'\/><\/div><div class=\"pbresults\" id=\"pyMultiResults0\"><\/div><div class=\"epilogue\">Korrekt! Obwohl <code>len(S)<\/code> dir die Gesamtzahl an Zeichen in der Zeichenkette herausgibt, da es mit dem Index <code>0<\/code> beginnt, ist das letzte Zeichen beim Index <code>len(S)-1<\/code>.<\/div><\/div>\n<p>Hier ist ein Beispiel der Verwendung von <code>len<\/code> und <code>[]<\/code>, den beiden Tools, die wir gerade eingef\u00fchrt haben.<br \/>\n<form class=\"pbform\" action=\"#\" id=\"pbform1\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox1'>\n<div class=\"heading\"><span class='type'>Example: <\/span><span class='title'>String length and characters<\/span><\/div> <div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 110px;'><textarea wrap='off' name='usercode1' id='usercode1'  cols=10 rows=4 readonly='readonly'  style = 'height : 110px;'  class='pyboxCode RO'>\nmagic = 'Abracadabra!'\nprint(magic)\nprint(len(magic))\nprint(magic[0], magic[1], magic[len(magic)-1])<\/textarea><\/div>\n<div id='pbhistory1' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit1' value=' '\/><\/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><\/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=\"a42dfcea7bc7e33ec723fa318accf4fa\"\/>\n<div id='pbresults1' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit1\").value = \"Run program\";document.getElementById(\"inputInUse1\").value = \"N\";<\/script>\n<\/p>\n<h2>Strings ausschneiden: <code>S[:]<\/code><\/h2>\n<p>Einen Teil eines Strings auszuschneiden ergibt einen <strong>Substring<\/strong> bzw. Teilstring. So sind zum Beispiel die Strings \"eat\" und \"ted\" Substrings von \"repeated\". Um einen Substring in Python auszuw\u00e4hlen, verwenden wir die Syntax:<\/p>\n<pre>S[firstIndex:tailIndex]<\/pre>um den Substring am Index <strong>firstIndex<\/strong> beginnen zu lassen und ihn enden zu lassen bei <strong>tailIndex-1<\/strong>.\u00a0 Versuche herauszufinden, was die Ausgabe des folgenden Codes ist, bevor du ihn ausf\u00fchrst.<br \/>\n<form class=\"pbform\" action=\"#\" id=\"pbform2\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox2'>\n<div class=\"heading\"><span class='type'>Example: <\/span><span class='title'>Substrings<\/span><\/div> <div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 110px;'><textarea wrap='off' name='usercode2' id='usercode2'  cols=10 rows=4 readonly='readonly'  style = 'height : 110px;'  class='pyboxCode RO'>\nmyString = 'Weighty'\nprint(myString[1:6])\nprint('magic'[3:3])\nprint('chump'[0:4])<\/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=\"45119d9534f7774b00f02ed90785927c\"\/>\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<\/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> Beachte, dass beim Ausschneiden eines Substrings firstIndex einbegriffen <strong>ist<\/strong>, aber der tailIndex <strong>nicht<\/strong>. Dies ist eine h\u00e4ufige Fehlerquelle. Sie hat jedoch ein paar nette Auswirkungen. Zum Beispiel ist aufgrund dieser Wahl die L\u00e4nge des Substrings <code>S[i:j]<\/code> immer <code>j-i<\/code>. <\/span><\/td><\/table><\/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'>Strings Rasieren<\/span><\/div>Schreibe ein Programm, das einen String liest, indem es <code>input()<\/code> verwendet, und den selben String ausgibt, aber mit dem Unterschied, dass das erste und letzte Zeichen gel\u00f6scht wird. (Du darfst annehmen, dass der Input String eine Mindestl\u00e4nge von 2 hat.) Zum Beispiel, bei der Eingabe <code>Fairy<\/code> wird ein korrektes Program <code>air<\/code> ausgeben.<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,'7a.firstlast')\" >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=\"6c3832f50d7daab240b82d9ed32638fe\"\/>\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>Strings einf\u00fcgen: <code>+<\/code><\/h2>\n<p>Wir wissen alle: 1+2=3. Mit Strings bekommen wir stattdessen das folgende Ergebnis:<br \/>\n<form class=\"pbform\" action=\"#\" id=\"pbform4\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox4'>\n<div class=\"heading\"><span class='type'>Example: <\/span><span class='title'>String Addition<\/span><\/div> <div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 84px;'><textarea wrap='off' name='usercode4' id='usercode4'  cols=10 rows=3 readonly='readonly'  style = 'height : 84px;'  class='pyboxCode RO'>\nresult = 'one' + 'two'\nprint(result)\nprint(len(result))<\/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=\"17788658f853df2c4a295747b177d580\"\/>\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>Wie du sehen kannst, erzeugt <code>S+T<\/code> einen neuen String, der mit\u00a0 <code>S<\/code> beginnt, worauf direkt <code>T<\/code> folgt. Diese \"String-Klebe-Operation\" nennt man auch <strong>Verkettung<\/strong> oder <strong>Konkatenation<\/strong>.<\/p>\n<p data-sider-select-id=\"fea0317e-fc36-4e51-abb0-7c14e81285b2\"><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'>Heads and Tails<\/span><\/div>Schreibe ein Programm, das einen String liest, indem es <code>input()<\/code> verwendet und den gleichen String ausgibt, aber mit dem ersten und letzten Zeichen <strong>vertauscht<\/strong>.\u00a0(Du darfst annehmen, dass der Input String eine Mindestl\u00e4nge von 2 hat.) Zum Beispiel wird bei der Eingabe <code>Fairy<\/code> ein korrektes Programm <code>yairF<\/code> ausgeben. Tipp: Verwende deine L\u00f6sung aus der vorherigen Programmier\u00fcbung: <em data-sider-select-id=\"ac0a5b5f-c5a1-4673-8f6b-0ffb5efbbef9\">Strings Rasieren<\/em>.<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'>\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<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,'7a.swap')\" >History<\/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=\"c5ee1959277f59799202dcf5b54357c5\"\/>\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<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 Zahlen verketten m\u00f6chtest, musst du sie zuerst zu str konvertieren. Sonst erh\u00e4ltst du einen von zwei Fehlern, je nachdem welche Reihenfolge du ausprobiert hast. F\u00fchre dieses Programm aus, um zu sehen, welche Fehler auftauchen k\u00f6nnen.<form class=\"pbform\" action=\"#\" id=\"pbform6\" method=\"POST\">\n<div class='pybox modeNeutral scramble facultative' id='pybox6'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>Arrangiere die Zeilen um, um zwei Verkettungsfehler zu sehen<ul class=\"pyscramble\" name=\"pyscramble\" id=\"pyscramble6\">\n <li class=\"pyscramble\">print(&quot;high &quot; + 5)<\/li>\n <li class=\"pyscramble\">print(110 + &quot; percent&quot;)<\/li>\n<\/ul>\n<input type='hidden' id='usercode6' name='usercode6'\/>\n<div id='pbhistory6' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit6' value=' '\/><\/td>\n<\/tr><\/table><\/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=\"42f55e078525cdaf706e417b10880dee\"\/>\n<div id='pbresults6' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit6\").value = \"Run program\";document.getElementById(\"inputInUse6\").value = \"N\";<\/script>\nHier ist ein korrektes Beispiel: die <code>str()<\/code> Funktion wandelt die Zahl zu einem String um vor der Verkettung.<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>Eine Zahl zu einem String umwandeln mithilfe von <code>str()<\/code><div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 32px;'><textarea wrap='off' name='usercode7' id='usercode7'  cols=10 rows=1 readonly='readonly'  style = 'height : 32px;'  class='pyboxCode RO'>\nprint(\"high \" + str(5))<\/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=\"daa4e48441b54e974cbdf799ca6e292e\"\/>\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 <\/span><\/td><\/table><\/p>\n<p>Wie wir bereits in Lektion 4 erw\u00e4hnt haben, kannst du Strings und Ganzzahlen multiplizieren: <code>S * n<\/code> ist kurz f\u00fcr <code>S + S + ... + S<\/code>.<\/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>String Multiplikation<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 58px;'><textarea wrap='off' name='usercode8' id='usercode8'  cols=10 rows=2 readonly='readonly'  style = 'height : 58px;'  class='pyboxCode RO'>\nprint(\"hots\" * 2)\nprint(\"mi\"+(\"s\"*2+\"i\")*2+\"ppi\")<\/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=\"925f6d8d9c2560c5cb1806844f936b21\"\/>\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>Zeichencodes: <code>ord<\/code>, <code>chr<\/code><a name=\"ord\"><\/a><\/h2>\n<p>Wie wir bereits in der Einleitung zu dieser Lektion erw\u00e4hnten, stellt dein Computer tats\u00e4chlich jedes Zeichen als Zahl dar. Welche Zahl entspricht welchem Zeichen? Allgemein gesprochen ist es davon abh\u00e4ngig, welche <em>Kodierung<\/em> dein Computer verwendet, aber nahezu alle modernen Computer haben eine Standardmenge an Zeichen f\u00fcr die Zahlen zwischen 32 und 255. Hier ist eine Liste der Zeichen mit Zahlen zwischen\u00a0 32 und 127:<\/p>\n<pre>ord: 32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47\nchr:      !   \"   #   $   %   &amp;   '   (   )   *   +   ,   -   .   \/\nord: 48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63\nchr:  0   1   2   3   4   5   6   7   8   9   :   ;   &lt;   =   &gt;   ?\nord: 64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79\nchr:  @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O\nord: 80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95\nchr:  P   Q   R   S   T   U   V   W   X   Y   Z   [   \\   ]   ^   _\nord: 96  97  98  99  100 101 102 103 104 105 106 107 108 109 110 111\nchr:  `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o\nord: 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127\nchr:  p   q   r   s   t   u   v   w   x   y   z   {   |   }   ~<\/pre>Sp\u00e4ter in Lektion 8 wirst du ein Programm schreiben, das diese Tabelle erzeugt.<br \/>\nEs ist nicht n\u00f6tig, die ganze Tabelle auswendig zu lernen, aber es gibt einige Fakten, die n\u00fctzlich zu erinnern sind:<\/p>\n<ul>\n<li>Die Kleinbuchstaben a, b, c, ..., z haben fortlaufende Zeichencodes.<\/li>\n<li>Die Gro\u00dfbuchstaben A, B, C, ..., Z haben fortlaufende Zeichencodes.<\/li>\n<li>Die Zahlen 0, 1, 2, ..., 9 haben fortlaufende Zeichencodes.<\/li>\n<\/ul>\n<p>Zeichen 32 ist ein Leerzeichen, und Zeichen 127 ist eines von mehreren besonderen \"Kontrollzeichen\". Einige hilfreiche Kontrollzeichen sind 9, was tab ist, und 10 und 13, die f\u00fcr <a href=\"https:\/\/de.wikipedia.org\/wiki\/Zeilenumbruch\">newlines<\/a> verwendet werden.<\/p>\n<p>In Python kannst du ein Zeichen in den ihm entsprechenden numerischen Code umwandeln, indem du die <code>ord<\/code> Funktion verwendest. Die\u00a0<code>chr<\/code> Funktion macht das genaue Gegenteil: sie nimmt eine Zahl als Input und gibt das Zeichen mit diesem Code wieder aus.<br \/>\n<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>Beispiele f\u00fcr <code>ord<\/code> und <code>chr<\/code> <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(ord('a'), ord('b'), ord('A'), ord('B'), ord(' '))\nprint(chr(35), chr(43), chr(100))<\/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=\"a351e1806345a8af896f5e992e2af359\"\/>\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<p><form class=\"pbform\" action=\"#\" id=\"pbform10\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox10'>\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'>Next Letter<\/span><\/div>Schreibe ein Programm, das ein Zeichen als Input nimmt (ein String der L\u00e4nge 1), von dem du annehmen solltest, das es ein Gro\u00dfbuchstabe ist. Ausgegeben werden sollte das n\u00e4chste Zeichen im Alphabet. Wenn der Input 'Z' ist, sollte dein Output 'A' sein. (Du wirst ein <code>if<\/code> Statement benutzen m\u00fcssen. Um einen weiteren Tipp zu erhalten, <a class=\"hintlink\"  id=\"hintlink11\">klicke hier<\/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='usercode10' id='usercode10'  cols=10 rows=20   class='pyboxCode RW'>\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory10' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput10\">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='submit10' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch10\" value=\"Input Switch\" onclick=\"pbInputSwitch(10,'N')\" ><\/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><select id='pbSelect10' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(10,'7a.lowercase')\" >History<\/option>\n<option name='help' data-pbonclick=\"helpClick(10);\" >Help<\/option>\n<\/select><\/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=\"4ff89248f98a3a15ee42cf4bf13ff0cd\"\/>\n<div id='pbresults10' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(10);});pbInputSwitch(10,\"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> Einige Systeme unterst\u00fctzen lediglich ausgebbare Zeichen zwischen 32 und 127, andere haben ausgebbare Zeichen bis zu 255 oder 65535; in Unicode gibt es hunderttausende Zeichen. Mehr dar\u00fcber kannst du <a href=\"http:\/\/en.wikipedia.org\/wiki\/American_Standard_Code_for_Information_Interchange\">hier<\/a> oder <a href=\"http:\/\/www.joelonsoftware.com\/articles\/Unicode.html\">hier<\/a> erfahren. <\/span><\/td><\/table><\/p>\n<p>Es gibt zwei weitere \u00dcbungen zum Abschluss der Lektion.<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform12\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox12'>\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'>Pig Latin<\/span><\/div><strong>Pig Latin<\/strong> ist eine Nonsenssprache. Um ein Wort aus dem Englischen zu Pig Latin zu transformieren, bewegt man den ersten Buchstaben an das Ende und f\u00fcgt danach \"ay\" an. Zum Beispiel verwandelt sich <em>monkey<\/em> in <em>onkeymay<\/em> und <em>word<\/em> wird zu<em> ordway<\/em>. Schreibe ein Programm, das ein einzelnes Wort als Input nimmt und es in Pig Latin \u00fcbersetzt. (Eigentlich sind die Regeln von Pig Latin komplizierter als wir es dargestellt haben, aber wir ignorieren diesen Umstand f\u00fcr diese Aufgabe.)<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='usercode12' id='usercode12'  cols=10 rows=20   class='pyboxCode RW'>\n# delete this comment and enter your code here\n<\/textarea><\/div>\n<div id='pbhistory12' class='flexcontain' style='display:none;'><\/div>\n<div name=\"pyinput\" id=\"pyinput12\">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='submit12' value=' '\/><\/td>\n<td><input type='button' name='switch' id=\"switch12\" value=\"Input Switch\" onclick=\"pbInputSwitch(12,'N')\" ><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(12)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(12,'N')\" ><\/td>\n<\/tr><\/table><select id='pbSelect12' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='history' data-pbonclick=\"historyClick(12,'7a.piglatin')\" >History<\/option>\n<option name='help' data-pbonclick=\"helpClick(12);\" >Help<\/option>\n<\/select><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse12\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"12\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"eb161e5a63f66ac0d38ec8929c1985e0\"\/>\n<div id='pbresults12' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(12);});pbInputSwitch(12,\"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'>The Name Game<\/span><\/div> Das <strong>Namensspiel<\/strong> erlaubt es dir, ein Lied aus dem Namen jeder Person zu machen. H\u00f6r dir das folgende Lied an, um zu verstehen, wie es funktioniert: <div style='text-align: center;'>\n<iframe width='560' height='315' src='https:\/\/www.youtube.com\/embed\/NeF7jqf0GU4?rel=0' frameborder='0' allowfullscreen>\n<\/iframe>\n<\/div> Dein Programm sollte den Namen einer Person als Input nehmen, zum Beispiel \"Pearl\" und das Lied folgenderma\u00dfen ausgeben<\/p>\n<pre>pearl, pearl, bo-bearl\nbanana-fana fo-fearl\nfee-fi-mo-mearl\npearl!<\/pre>Du siehst, dass der komplette Name dreimal auftaucht; zus\u00e4tzlich erscheint der Name drei weitere Male, wobei der erste Buchstabe ausgetauscht wurde durch ein b, f oder m.. (Eigentlich sind die Regeln dieses Liedes komplizierter als wir es dargestellt haben, aber wir ignorieren diesen Umstand f\u00fcr diese Aufgabe.)<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,'7a.namegame')\" >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=\"79db51379b935112cdd529a487fb0d4b\"\/>\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><em>Du kannst dich nun der n\u00e4chsten Lektion widmen!<br \/>\n<\/em><\/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 Zeichenketten bzw. Strings (Elemente vom Typ str ) nur auf ganz einfache Art und Weise verwendet. In dieser Lektion zeigen &hellip; <a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/7a-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-5563","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5563","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=5563"}],"version-history":[{"count":35,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5563\/revisions"}],"predecessor-version":[{"id":15911,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/5563\/revisions\/15911"}],"wp:attachment":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/media?parent=5563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}