{"id":9301,"date":"2016-06-07T23:30:06","date_gmt":"2016-06-08T03:30:06","guid":{"rendered":"http:\/\/cscircles.cemc.uwaterloo.ca\/?page_id=9301"},"modified":"2017-06-28T18:49:23","modified_gmt":"2017-06-28T22:49:23","slug":"zh-13","status":"publish","type":"page","link":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/zh-13\/","title":{"rendered":"13: \u5e8f\u5217 (\u6570\u7ec4)"},"content":{"rendered":"<!-- Please retain this notice and add more notes if you create a new version.<br \/>\nOriginal lesson author: David Pritchard, daveagp@gmail.com, http:\/\/cscircles.ca<br \/>\nLicense: http:\/\/creativecommons.org\/licenses\/by-nc-sa\/3.0\/-->\n<p><strong>\u5e8f\u5217<\/strong>\u662f\u4e00\u4e32\u53d8\u91cf\u96c6\u5408\u5728\u4e00\u8d77\uff0c\u4ee5\u540c\u4e00\u4e2a\u540d\u5b57\u547d\u540d\u3002\u5e8f\u5217\u4e0d\u50cf\u662f\u4e00\u4e2a\u6709\u5f88\u591a\u53d8\u91cf<code>x0<\/code>, <code>x1<\/code>, <code>x2<\/code>\u7684\u7a0b\u5e8f\uff0c\u800c\u66f4\u50cf\u662f\u4e00\u4e2a\u53d8\u91cf<code>x<\/code>\uff0c\u5e76\u80fd\u591f\u63d0\u53d6\u5176\u4e2d\u7684\u6210\u5458<code>x[0]<\/code>, <code>x[1]<\/code>, <code>x[2]<\/code>\u7b49\u3002\u4f60\u8fd8\u53ef\u4ee5\u5c06\u5176\u4ed6\u7684\u8868\u8fbe\u5f0f\u548c\u53d8\u91cf\u653e\u5728\u4e2d\u62ec\u53f7\u91cc\uff0c\u6bd4\u5982<code>x[i]<\/code>\u548c<code>x[i+1]<\/code>\u3002\u8fd9\u8ba9\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ec5\u4f7f\u7528\u4e00\u5c0f\u6bb5\u4ee3\u7801\u5904\u7406\u4efb\u610f\u5927\u7684\u6570\u636e\u3002<\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u5e8f\u5217\u7684\u65b9\u5f0f\u662f\u628a\u4e00\u4e9b\u503c\u5408\u5728\u4e00\u8d77\uff0c\u653e\u5728\u4e2d\u62ec\u53f7\u91cc\uff0c\u5e76\u7528\u9017\u53f7\u7ed9\u9694\u5f00\uff1a<\/p>\n<pre>myList = [\"the first value in the list\", 1999, 4.5]<\/pre>\u8fd9\u521b\u5efa\u4e86\u4e00\u4e2a\u5e8f\u5217\uff0c\u540d\u4e3a<code>myList<\/code>\uff0c\u957f\u5ea6\u4e3a3\u3002\u5e8f\u5217\u7684\u6bcf\u4e00\u9879\u90fd\u6709\u4e00\u4e2a\u540d\u4e3a<strong>index<\/strong>\u7684\u6570\u5b57\u5bf9\u5e94\uff1a\u7b2c\u4e00\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u662f0\uff0c\u4e0b\u4e00\u4e2a\u5143\u7d20\u7d22\u5f15\u662f1\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u5355\u4e2a\u7684\u53d8\u91cf\u7531\u5e8f\u5217\u6784\u6210\uff0c\u540d\u5b57\u662f<\/p>\n<p style=\"text-align: center;\"><code>\u00ablistName\u00bb[\u00abindexNumber\u00bb]<\/code><\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>myList[0]<\/code>\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u53d8\u91cf\u7684\u503c\u662f\u5b57\u7b26\u4e32<code>\"the first value in the list\"<\/code>\u548c<code>print(myList[2])<\/code> <a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/console\/?consolecode=myList%20%3D%20%5B%22the%20first%20value%20in%20the%20list%22%2C%201999%2C%204.5%5D%0Aprint%28myList%5B2%5D%29\" target=\"_blank\">would print<\/a> <code>4.5<\/code>\u3002\u4f60\u4e5f\u53ef\u4ee5\u6539\u53d8\u5e8f\u5217\u4e2d\u6bcf\u4e00\u9879\u7684\u503c\uff0c\u5e76\u5c06\u6574\u4e2a\u5e8f\u5217\u6253\u5370\u51fa\u6765\uff1a<\/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>\u66f4\u65b0\u5e76\u6253\u5370\u5e8f\u5217\u3002<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 84px;'><textarea wrap='off' name='usercode0' id='usercode0'  cols=10 rows=3 readonly='readonly'  style = 'height : 84px;'  class='pyboxCode RO'>\nnumbers = ['zero', 'one', 'two']\nnumbers[0] = 'zilch'\nprint(numbers)<\/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=\"d82a0deb4b4717421add40670f2e07b9\"\/>\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>\u6b63\u5982\u4f60\u6240\u770b\u5230\u7684\u90a3\u6837\uff0c<code>numbers[0]<\/code>\u88ab\u5f53\u4f5c\u6210\u4e00\u4e2a\u53d8\u91cf\uff1a\u62e5\u6709\u4e00\u4e2a\u503c\uff0c\u8fd9\u4e2a\u503c\u4e5f\u53ef\u4ee5\u6539\u53d8\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u5c1d\u8bd5\u9884\u6d4b\u4e0b\u5217\u4f8b\u5b50\u7684\u6700\u540e\u72b6\u6001\uff0c\u7136\u540e\u4e0e\u5b9e\u9645\u60c5\u51b5\u6bd4\u5bf9\u3002<\/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=myList+%3D+%5B1%2C+10%2C+100%2C+1000%5D%0Afor+i+in+range%280%2C+2%29%3A%0A++myList%5Bi%5D+%3D+2%2AmyList%5Bi%5D%2Bi&cumulative=false&heapPrimitives=false&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=3&curInstr=0&resizeContainer=true&highlightLines&width=350&rightStdout=1'><\/iframe><\/p>\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'>Multiple Choice Exercise: <\/span><span class='title'>\u5143\u4fe1\u606f<\/span><\/div><div>\u4e0b\u5217\u4ee3\u7801\u7684\u8f93\u51fa\u662f\u4ec0\u4e48?<\/p>\n<pre>stuff = [2, 25, 80, 12]\r\nstuff[stuff[0]] = stuff[3]\r\nprint(stuff)<\/pre><\/div><label>Your choice: <\/label><select id=\"pyselect1\"><option value=\"d\" selected>Select one<\/option><option value=\"w\">[12, 25, 80, 12]<\/option><option value=\"r\">[2, 25, 12, 12]<\/option><option value=\"w\">[2, 25, 80, 80]<\/option><option value=\"w\">\u8fd9\u4e2a\u4ee3\u7801\u6709\u95ee\u9898\u3002<\/option><option value=\"w\">[2, 25, 80, 12]<\/option><\/select><div class='pyboxbuttons'><input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" name=\"slug\" value=\"13.indexindex\"\/><input type='submit' style='margin:5px;' value='Check answer' onClick='pbMultiCheck(1)'\/><\/div><div class=\"pbresults\" id=\"pyMultiResults1\"><\/div><div class=\"epilogue\">\u6b63\u786e\uff01\u8bf7\u770b\u6307\u5b9a\u9648\u8ff0\uff08\u7b2c\u4e8c\u884c\uff09\u3002\u53f3\u4fa7\u7684<code>stuff[3]<\/code>\u7684\u503c<code>12<\/code>\u3002\u5728\u5de6\u4fa7\uff0c<code>stuff[0]<\/code>\u662f<code>2<\/code>\uff0c\u6240\u4ee5<code>stuff[stuff[0]]<\/code>\u4ee3\u8868\u4e86\u53d8\u91cf<code>stuff[2]<\/code>\u3002\u8fd9\u4e2a\u53d8\u91cf\u7684\u503c\u88ab\u66f4\u65b0\uff08\u4ece<code>80<\/code>\uff09\u5230<code>12<\/code>\u3002<\/div><\/div>\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\u91cc\u9762\u7684<strong>\u5e8f\u5217<\/strong>\u5728\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u91cc\u9762\u88ab\u53eb\u505a<strong>\u6570\u7ec4<\/strong>\u3002Python \u91cc\u6709\u4e00\u4e9b\u4e0d\u540c\u4e14\u66f4\u52a0\u9ad8\u7ea7\u7684\u4e1c\u897f&amp;amp\uff0c\u4e5f\u88ab\u79f0\u4f5c\u6570\u7ec4\u3002 <\/span><\/td><\/table><\/p>\n<h3>\u5e38\u89c1\u7684\u9519\u8bef<\/h3>\n<p>\u5728Python\u91cc\uff0c\u8c03\u7528\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u7d22\u5f15\u4f1a\u5f97\u5230\u9519\u8bef\u63d0\u793a\uff1a<\/p>\n<p><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>\u8303\u56f4\u5916\u9519\u8bef\u3002<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'>\nmyList=[1, 2, 4, 8]\nprint(myList[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=\"d236bc08f9f6bf1c1ceac57fa1675129\"\/>\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>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u56e0\u4e3a<code>myList<\/code>\u957f\u5ea6\u4e3a4\uff0c\u7b2c\u4e00\u4e2a\u7d22\u5f15\u662f0\uff0c\u6700\u5927\u53ef\u80fd\u7684\u7d22\u5f15\u503c\u662f3\u3002\u5982\u679c\u60f3\u8981\u7d22\u5f154\u62165\uff0c\u6216\u66f4\u5927\u7684\u7d22\u5f15\u503c\uff0c\u5c31\u4f1a\u6536\u5230\u9519\u8bef\u63d0\u793a\u3002<\/p>\n<p><span style=\"color: #000000; font-size: 23px; line-height: 35px;\">\u5e38\u89c1\u6709\u7528\u7684\u8fd0\u7b97<\/span><\/p>\n<h3>\u5e8f\u5217\u7684\u957f\u5ea6: <code>len(\u00ablist\u00bb)<\/code><\/h3>\n<p>\u4e3a\u4e86\u5f97\u51fa\u5e8f\u5217\u4e2d\u9879\u76ee\u7684\u4e2a\u6570\uff0c\u5728\u8be5\u5e8f\u5217\u4e0a\u8fd0\u7528\u65b9\u7a0b<code>len()<\/code>\u3002\u67e5\u770b<code>range<\/code>\u662f\u5982\u4f55\u5728\u4e0b\u5217\u4f8b\u5b50\u4e2d\u4f7f\u7528\u7684\u3002<\/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>\u5f97\u5230\u5e8f\u5217\u7684\u957f\u5ea6\uff0c\u4f7f\u7528\u5176\u7ed3\u679c\u6765\u5bf9\u5e8f\u5217\u8fed\u4ee3\u3002<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 110px;'><textarea wrap='off' name='usercode3' id='usercode3'  cols=10 rows=4 readonly='readonly'  style = 'height : 110px;'  class='pyboxCode RO'>\nmyList = [3, 12, \"pizza\", 3, 4]\nprint(\"myList has length\", len(myList))\nfor i in range(0, len(myList)):\n  print(\"item at index\", i, \":\", myList[i])<\/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=\"f3dbb38901f088264cb9c514967aa74e\"\/>\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>\u901a\u5e38\u4f7f\u7528len \u6765\u7f16\u5199\u4ee3\u7801\uff0c\u8fd9\u4e9b\u4ee3\u7801\u53ef\u4ee5\u7528\u4e8e\u4efb\u4f55\u957f\u5ea6\u7684\u5e8f\u5217\uff0c\u6b63\u5982\u4e0a\u9762\u7684\u4f8b\u5b50\u548c\u4e0b\u9762\u7684\u7ec3\u4e60\u4e00\u6837\u3002<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform4\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox4'>\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'>Monkey in the Middle<\/span><\/div>\u7f16\u5199\u4e00\u4e2a\u65b9\u7a0b<code>middle(L)<\/code>\uff0c\u5c06\u5e8f\u5217L \u4f5c\u4e3a\u5b83\u7684\u5b9e\u53c2\uff0c\u8fd4\u8fd8<code>L<\/code>\u7684<em>\u4e2d\u95f4<\/em>\u9879\uff08\u5047\u8bbe<code>L<\/code>\u662f\u5947\u6570\u957f\u5ea6\uff09\u3002\u6bd4\u5982\uff0c<code>middle([8, 0, 100, 12, 1])<\/code>\u4f1a\u8fd4\u8fd8<code>100<\/code>\uff0c\u56e0\u4e3a100\u662f\u6b63\u5f53\u4e2d\u7684\u9879\u3002<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='usercode4' id='usercode4'  cols=10 rows=20   class='pyboxCode RW'>\ndef...\n<\/textarea><\/div>\n<div id='pbhistory4' class='flexcontain' style='display:none;'><\/div>\n<input type='hidden' id='defaultCode4' value='def...\\n'><\/input>\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,'Y')\" ><\/td>\n<td><input type='button' name='history' value=\"History\" onclick=\"historyClick(4,'13.middle')\" ><\/td>\n<\/tr><\/table><select id='pbSelect4' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='default' data-pbonclick=\"pbSetText(4,descape($('#defaultCode4').val()))\" >Reset code to default<\/option>\n<option name='help' data-pbonclick=\"helpClick(4);\" >Help<\/option>\n<\/select><\/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=\"41d15d48b67c93ad5f1f31be721344bd\"\/>\n<div id='pbresults4' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(4);});document.getElementById(\"submit4\").value = \"Run program\";document.getElementById(\"inputInUse4\").value = \"N\";<\/script>\n<\/p>\n<h3>\u5e8f\u5217\u548c\u5b57\u7b26\u4e32\u4e00\u6837\u4e48\uff1f<\/h3>\n<p>\u4f60\u53ef\u80fd\u5df2\u7ecf\u6ce8\u610f\u5230\u4e86\u6709\u5173\u5e8f\u5217\u7684\u65b9\u7a0b\u4e0e\u5b57\u7b26\u4e32\u7684\u65b9\u7a0b\u76f8\u4f3c\uff1a\u4e24\u4e2a\u90fd\u80fd\u4f7f\u7528<code>len()<\/code>\u65b9\u7a0b\u6765\u83b7\u5f97\u957f\u5ea6\uff0c\u4e24\u4e2a\u90fd\u80fd\u4f7f\u7528<code>X[\u00abindex\u00bb]<\/code>\u6765\u63d0\u53d6\u51fa\u4e2a\u4f53\u3002\u5e8f\u5217\u548c\u5b57\u7b26\u4e32\u5b9e\u9645\u4e0a\u662f\u76f8\u5173\u7684\uff1a\u5b83\u4eec\u90fd\u662fPython\u4e2d\u7684\"<a href=\"http:\/\/docs.python.org\/py3k\/library\/stdtypes.html?highlight=sequence#sequence-types-str-bytes-bytearray-list-tuple-range\">\u5e8f\u5217\u7c7b\u578b<\/a>\"\u3002\u5176\u4e2d\u4e00\u4e2a\u4e3b\u8981\u7684\u533a\u522b\u5728\u4e8e\u5b57\u7b26\u4e32\u4e2d\u5355\u4e2a\u7684\u5b57\u7b26\u4e0d\u80fd\u88ab\u6539\u53d8\u3002<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform5\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox5'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>\u5c1d\u8bd5\u5c06\u4e00\u4e2a\u503c\u5f52\u4e8e\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e2a\u5b57\u7b26\u5bfc\u81f4\u4e86\u9519\u8bef\u3002<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 84px;'><textarea wrap='off' name='usercode5' id='usercode5'  cols=10 rows=3 readonly='readonly'  style = 'height : 84px;'  class='pyboxCode RO'>\nword='slack'\nprint(word, word[1])\nword[1]='n'<\/textarea><\/div>\n<div id='pbhistory5' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit5' value=' '\/><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(5)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(5,'N')\" ><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse5\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"5\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"071e91b26fabcbb7947f2acafc8ec3ec\"\/>\n<div id='pbresults5' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit5\").value = \"Run program\";document.getElementById(\"inputInUse5\").value = \"N\";<\/script>\n<\/p>\n<p>\u56e0\u4e3a\u8fd9\u4e2a\u539f\u56e0\uff0c\u5e8f\u5217\u88ab\u79f0\u4f5c<em>\u53ef\u6539\u53d8\u7684<\/em>\u7c7b\u578b\uff0c\u5b57\u7b26\u4e32\u662f<em>\u4e0d\u53ef\u6539\u53d8\u7684<\/em>\uff1b\u4f60\u4f1a\u5728\u7b2c17\u8bfe\u770b\u5230\u6709\u5173\u4e8e\u6b64\u7684\u4fe1\u606f\u3002<\/p>\n<h3>\u4e32\u8054\u4e0e\u521b\u9020<\/h3>\n<p>\u5728\u6709\u5173<code>str<\/code>\u7c7b\u578b\u7684<a href=\"\/7a-strings\/\">\u8fd9\u4e00\u8bfe<\/a>\uff0c\u4f60\u53ef\u80fd\u8bb0\u5f97\u53ef\u4ee5\u4f7f\u7528<code>+<\/code>\u6765\u878d\u5408\uff08<em>\u4e32\u8054<\/em>\uff09\u4e24\u4e2a\u5b57\u7b26\u4e32\u3002\u4f60\u53ef\u4ee5\u5bf9\u5e8f\u5217\u505a\u540c\u6837\u7684\u4e8b\u60c5\uff1a<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform6\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox6'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>\u4f7f\u7528<code>+<\/code>\u5408\u5e76\u6570\u5217\u3002<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 136px;'><textarea wrap='off' name='usercode6' id='usercode6'  cols=10 rows=5 readonly='readonly'  style = 'height : 136px;'  class='pyboxCode RO'>\nlistA = [3, 'go', 7.1]\nlistB = [4, 'hi', 1]\nlistC = listA + listB\nprint(len(listC))\nprint(listC)<\/textarea><\/div>\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<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(6)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(6,'N')\" ><\/td>\n<\/tr><\/table><\/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=\"9de0c01c5030f213b37d8ba3491ec8f8\"\/>\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>\n<\/p>\n<p>\u540c\u6837\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e58\u6cd5\u7b26\u53f7<code>*<\/code>\u6765\u901a\u8fc7\u91cd\u590d\u6269\u5145\u4e00\u4e2a\u5e8f\u5217\u3002\u8fd9\u6709\u52a9\u4e8e\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u56fa\u5b9a\u957f\u5ea6\u7684\u5e8f\u5217\u3002<\/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>\u4f7f\u7528<code><code>*<\/code><\/code>\u3002<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 110px;'><textarea wrap='off' name='usercode7' id='usercode7'  cols=10 rows=4 readonly='readonly'  style = 'height : 110px;'  class='pyboxCode RO'>\nmyPhoneNumber = [9, 6, 7] + [1]*4\nprint(myPhoneNumber)\nnewEmptyList = [0]*20\nprint(newEmptyList)<\/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=\"b3108d3ef8326dc1609d500870b8d584\"\/>\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>\u4e0b\u4e00\u4e2a\u7ec3\u4e60\u9898\u9700\u8981\u4f7f\u7528\u6211\u4eec\u521a\u4ecb\u7ecd\u7684\u4e00\u4e2a\u8fd0\u7b97\u7b26\uff0c\u4ee5\u53ca<code>for<\/code>\u5faa\u73af\u3002<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform8\" method=\"POST\">\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'>Coding Exercise: <\/span><span class='title'>It's Natural<\/span><\/div>\u7f16\u5199\u4e00\u4e2a\u65b9\u7a0b<code>naturalNumbers<\/code>\uff0c\u9700\u8981\u4e00\u4e2a\u6b63\u6574\u6570<code>n<\/code>\u4f5c\u4e3a\u8f93\u5165\uff0c\u8fd4\u8fd8\u4e00\u4e2a\u7531\u524d<code>n<\/code>\u4e2a\u81ea\u7136\u6570\u7ec4\u6210\u7684\u5e8f\u5217<code>[1, 2, ...]<\/code>\u3002<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='usercode8' id='usercode8'  cols=10 rows=20   class='pyboxCode RW'>\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,'Y')\" ><\/td>\n<td><input type='button' name='history' value=\"History\" onclick=\"historyClick(8,'13.natural')\" ><\/td>\n<\/tr><\/table><select id='pbSelect8' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='help' data-pbonclick=\"helpClick(8);\" >Help<\/option>\n<\/select><\/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=\"3251ce6d30b0a103114470f10abbe17c\"\/>\n<div id='pbresults8' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(8);});document.getElementById(\"submit8\").value = \"Run program\";document.getElementById(\"inputInUse8\").value = \"N\";<\/script>\n<\/p>\n<h3>\u884c\u672b\uff1a\u8d1f\u6307\u6570<\/h3>\n<p>\u4e3a\u4e86\u5f97\u5230\u5e8f\u5217\u7684\u6700\u540e\u4e00\u9879\uff0c\u4f7f\u7528<\/p>\n<p style=\"text-align: center;\"><code>\u00ablistName\u00bb[-1]<\/code><\/p>\n<p>\u4e00\u822c\u6765\u8bf4\uff0c<code>L[-k]<\/code>\u8fd4\u8fd8\u5e8f\u5217\u5012\u6570\u7b2c<code>k<\/code>\u4e2a\u9879\uff1bPython\u901a\u8fc7\u5c06\u5176\u8f6c\u5316\u6210<code>L[len(L)-k]<\/code>\u4ece\u5185\u90e8\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u8fd9\u4e2a\u5feb\u6377\u7b26\u53f7\u5bf9\u5b57\u7b26\u4e32\u4e5f\u9002\u7528\uff01<\/p>\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'>\u56de\u6587<\/span><\/div><em>\u56de\u6587<\/em>\u610f\u5473\u7740\u4e00\u4e2a\u8bcd\u6b63\u7740\u770b\uff0c\u5012\u7740\u770b\u90fd\u4e00\u6837\u3002\u6bd4\u5982\uff0c<\/p>\n<p style=\"text-align: center;\"><code>racecar<\/code><\/p>\n<p>\u56de\u6587\uff1a\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd\u90fd\u662fr\uff0c\u7b2c\u4e8c\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u5b57\u6bcd\u90fd\u662fa\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u7f16\u5199\u4e00\u4e2a\u65b9\u7a0b<code>isPalindrome(S)<\/code>\uff0c\u9700\u8981\u4e00\u4e2a\u5b57\u7b26\u4e32<code>S<\/code>\u4f5c\u4e3a\u8f93\u5165\uff0c\u5982\u679c\u5b57\u7b26\u4e32\u662f\u4e00\u4e2a\u56de\u6587\u8bcd\uff0c\u8fd4\u8fd8True\uff0c\u5426\u5219\u4e3aFalse\u3002<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'>\n<\/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,'Y')\" ><\/td>\n<td><input type='button' name='history' value=\"History\" onclick=\"historyClick(9,'13.palindrome')\" ><\/td>\n<\/tr><\/table><select id='pbSelect9' class='selectmore'><option name='more'>More actions...<\/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=\"2d94de0c5dd526986c4e0e4d88bdf427\"\/>\n<div id='pbresults9' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(9);});document.getElementById(\"submit9\").value = \"Run program\";document.getElementById(\"inputInUse9\").value = \"N\";<\/script>\n<\/p>\n<h3><code>max<\/code>\u548c<code>sum<\/code><\/h3>\n<p>\u6211\u4eec\u4e4b\u524d\u89c1\u5230\u7684\u65b9\u7a0bmax \u4e5f\u53ef\u4ee5\u7528\u4e8e\u5e8f\u5217\u6570\u5b57\uff1a\u5b83\u8fd4\u8fd8\u5e8f\u5217\u4e2d\u6700\u5927\u7684\u6570\u5b57\u3002\u540c\u6837\uff0c\u65b9\u7a0b<code>sum(L)<\/code>\u8fd4\u8fd8\u5e8f\u5217<code>L<\/code>\u4e2d\u6240\u6709\u9879\u7684\u548c\u3002<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform10\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox10'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div><div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 84px;'><textarea wrap='off' name='usercode10' id='usercode10'  cols=10 rows=3 readonly='readonly'  style = 'height : 84px;'  class='pyboxCode RO'>\nlist = [3, 10, 4, 9, 0]\nprint(sum(list))\nprint(max(list))<\/textarea><\/div>\n<div id='pbhistory10' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit10' value=' '\/><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(10)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(10,'N')\" ><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse10\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"10\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"8391f798f13bdcc5e3debef1c0636f8c\"\/>\n<div id='pbresults10' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit10\").value = \"Run program\";document.getElementById(\"inputInUse10\").value = \"N\";<\/script>\n<\/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'>Product<\/span><\/div>\u5b9a\u4e49\u4e00\u4e2a\u65b9\u7a0b<code>prod(L)<\/code>\uff0c\u8fd4\u8fd8\u5e8f\u5217<code>L<\/code>\u4e2d\u6240\u6709\u9879\u7684\u4e58\u79ef\u3002<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'>\n<\/textarea><\/div>\n<div id='pbhistory11' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit11' value=' '\/><\/td>\n<td><input type='button' name='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(11)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(11,'Y')\" ><\/td>\n<td><input type='button' name='history' value=\"History\" onclick=\"historyClick(11,'13.product')\" ><\/td>\n<\/tr><\/table><select id='pbSelect11' class='selectmore'><option name='more'>More actions...<\/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=\"f22967a9b4c36803def4d45a167e1331\"\/>\n<div id='pbresults11' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(11);});document.getElementById(\"submit11\").value = \"Run program\";document.getElementById(\"inputInUse11\").value = \"N\";<\/script>\n<\/p>\n<h3>\u5faa\u73af\u5e8f\u5217<\/h3>\n<p>\u5c06\u4e00\u4e2a\u5e8f\u5217\u4e2d\u6bcf\u4e00\u4e2a\u503c\u90fd\u5faa\u73af\uff08\u4e0e\u524d\u9762\u7684\u4f8b\u5b50\u7c7b\u4f3c\uff09\u662f\u975e\u5e38\u666e\u904d\u7684\u3002Python\u4e2d\u6709\u4e00\u4e2a\u5feb\u6377\u65b9\u5f0f\u6765\u8fdb\u884c\u8fd9\u9879\u64cd\u4f5c\uff0c\u901a\u5e38\u88ab\u79f0\u4e3a<em>\"for all\"\u5faa\u73af<\/em>\uff0c\u6216\u8005<em>\"for each\"\u5faa\u73af<\/em>\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u5f53L\u662f\u4e00\u4e2a\u5e8f\u5217\uff0c\u8fd9\u4e2a\u4ee3\u7801<\/p>\n<pre>for x in L:\r\n  \u00abloop body block\u00bb<\/pre>\u8fdb\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a\u7b2c\u4e00\u4e2a<code>x<\/code>\u88ab\u8bbe\u7f6e\u6210<code>L<\/code>\u5e8f\u5217\u4e2d\u7b2c\u4e00\u9879\uff0c\u7136\u540e\u8fd0\u884c\u4e3b\u4f53\uff1b\u7136\u540e<code>x<\/code>\u518d\u88ab\u8bbe\u7f6e\u6210<code>L<\/code>\u5e8f\u5217\u4e2d\u7b2c\u4e8c\u9879\uff0c\u7136\u540e\u8fd0\u884c\u4e3b\u4f53\uff1b\u4ee5\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230<code>L<\/code>\u5e8f\u5217\u91cc\u9762\u7684\u6240\u6709\u9879\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u53ef\u89c6\u5316\u7684\u4f8b\u5b50\uff0c\u6765\u6253\u5370\u51fa\u5e8f\u5217\u4e2d\u7684\u9879\uff1a<\/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=message%3D%5B%27s%27%2C+%27o%27%2C+%27s%27%5D%0Afor+x+in+message%3A%0A++print%28x%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><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'><code>for in<\/code><\/span><\/div>\u5b9a\u4e49\u65b9\u7a0b<code>prod(L)<\/code>\uff0c\u4f46\u662f\u8fd9\u4e00\u6b21\u4f7f\u7528\u65b0\u7684\u5faa\u73af\u3002<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<\/textarea><\/div>\n<div id='pbhistory12' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit12' value=' '\/><\/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,'Y')\" ><\/td>\n<td><input type='button' name='history' value=\"History\" onclick=\"historyClick(12,'13.foreach')\" ><\/td>\n<\/tr><\/table><select id='pbSelect12' class='selectmore'><option name='more'>More actions...<\/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=\"fb403d2b66c2c7f7157c35b00619ef85\"\/>\n<div id='pbresults12' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(12);});document.getElementById(\"submit12\").value = \"Run program\";document.getElementById(\"inputInUse12\").value = \"N\";<\/script>\n<\/p>\n<p>\"For all\"\u5faa\u73af\u4e5f\u9002\u7528\u4e8e\u5b57\u7b26\u4e32\uff1a\u5c1d\u8bd5<code><a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/console\/?consolecode=for%20char%20in%20%22hello%22%3A%20print%28char%29\" target=\"_blank\">for char in \"hello\"<\/a><\/code>.<\/p>\n<p><em>\u505a\u5f97\u597d\uff01\u73b0\u5728\u4f60\u53ef\u4ee5\u8fdb\u884c\u4e0b\u4e00\u8bfe\u7684\u5b66\u4e60\u4e86\uff0c\u6216\u8005\u4f60\u53ef\u4ee5\u8bd5\u8bd5\u4e0b\u9762\u7684\u7ec3\u4e60\u9898\u3002<\/em><\/p>\n<hr \/>\n<p><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'>Short Answer Exercise: <\/span><span class='title'>Mystery Function<\/span><\/div><code>x<\/code>\u4e3a\u4f55\u503c\u65f6\uff0c\u4f1a\u4f7f<code>mystery(x)<\/code>\u4e00\u76f4\u8fd0\u884c\u4e0b\u53bb\uff1f<\/p>\n<pre>def mystery(x):\r\n  a = [0, 4, 0, 3, 2]\r\n  while x &gt; 0:\r\n    x = a[x]\r\n  return \"Done\"<\/pre><label for=\"pyShortAnswer13\">Your answer: <\/label><input type=\"text\" onkeypress=\"{if (event.keyCode==13) pbShortCheck(13)}\" id=\"pyShortAnswer13\"><div class=\"pyboxbuttons\"><input type=\"hidden\" name=\"type\" value=\"trimmableString\"\/><input type=\"hidden\" name=\"correct\" value=\"3\"\/><input type=\"hidden\" name=\"slug\" value=\"13.mystery\"\/><input type=\"hidden\" name=\"lang\" value=\"\"\/><input type='submit' style='margin:5px;' value='Check answer' onClick = 'pbShortCheck(13)'\/><\/div><div class=\"pbresults\" id=\"pyShortResults13\"><\/div><div class=\"epilogue\">Correct!<\/div><\/div>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform14\" method=\"POST\">\n<div class='pybox modeNeutral scramble' id='pybox14'>\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'>Scramble Exercise: <\/span><span class='title'>\u00e0 la Mode<\/span><\/div>\u4e00\u4e2a\u5e8f\u5217\u7684<em>\u4f17\u6570<\/em>\u662f\u51fa\u73b0\u6b21\u6570\u6700\u591a\u7684\u6570\u5b57\uff08\u9891\u7387\u6700\u5927\uff09\u3002\u6574\u7406\u4e0b\u9762\u7684\u7a0b\u5e8f\uff0c\u4f7f\u5f97<code>mode(L)<\/code>\u80fd\u591f\u6b63\u786e\u5730\u627e\u5230\u4f17\u6570\uff0c\u5047\u8bbe<code>L<\/code>\u662f\u4e00\u4e2a\u7531\u4ece0\u52309\u6570\u5b57\u7ec4\u6210\u7684\u5e8f\u5217\uff08\u4e0d\u5fc5\u8003\u8651\u51fa\u73b0\u4e24\u4e2a\u6570\u5b57\u62e5\u6709\u540c\u6837\u7684\u9891\u7387\u7684\u60c5\u51b5\uff09\u3002<ul class=\"pyscramble\" name=\"pyscramble\" id=\"pyscramble14\">\n <li class=\"pyscramble\">  frequency = [0]*10<\/li>\n <li class=\"pyscramble\">  for i in L:<\/li>\n <li class=\"pyscramble\">def mode(L):<\/li>\n <li class=\"pyscramble\">    if frequency[i]==max(frequency):<\/li>\n <li class=\"pyscramble\">    frequency[i] = frequency[i] + 1<\/li>\n <li class=\"pyscramble\">  for i in range(0, 10):<\/li>\n <li class=\"pyscramble\">      return i<\/li>\n<\/ul>\n<input type='hidden' id='usercode14' name='usercode14'\/>\n<div id='pbhistory14' class='flexcontain' style='display:none;'><\/div>\n<div class='pyboxbuttons'><table><tr>\n<td><input type='submit' name='submit' id='submit14' value=' '\/><\/td>\n<\/tr><\/table><\/div>\n<input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" id=\"inputInUse14\" name=\"inputInUse\" value=\"Y\"\/>\n<input type=\"hidden\" name=\"pyId\" value=\"14\"\/>\n<input type=\"hidden\" name=\"hash\" value=\"eb28fafe2e15b7d63b2120819163c0b8\"\/>\n<div id='pbresults14' class='pbresults'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>document.getElementById(\"submit14\").value = \"Run program\";document.getElementById(\"inputInUse14\").value = \"N\";<\/script>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e8f\u5217\u662f\u4e00\u4e32\u53d8\u91cf\u96c6\u5408\u5728\u4e00\u8d77\uff0c\u4ee5\u540c\u4e00\u4e2a\u540d\u5b57\u547d\u540d\u3002\u5e8f\u5217\u4e0d\u50cf\u662f\u4e00\u4e2a\u6709\u5f88\u591a\u53d8\u91cfx0, x1, x2\u7684\u7a0b\u5e8f\uff0c\u800c\u66f4\u50cf\u662f\u4e00\u4e2a\u53d8\u91cfx\uff0c\u5e76\u80fd\u591f\u63d0\u53d6\u5176\u4e2d\u7684\u6210\u5458x[0], x[1], x[2]\u7b49\u3002\u4f60\u8fd8\u53ef\u4ee5\u5c06\u5176\u4ed6\u7684\u8868\u8fbe\u5f0f\u548c\u53d8\u91cf\u653e\u5728\u4e2d\u62ec\u53f7\u91cc\uff0c\u6bd4\u5982x[i]\u548cx[i+1]\u3002\u8fd9\u8ba9\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ec5\u4f7f\u7528\u4e00\u5c0f\u6bb5\u4ee3\u7801\u5904\u7406\u4efb\u610f\u5927\u7684\u6570\u636e\u3002 \u521b\u5efa\u4e00\u4e2a\u5e8f\u5217\u7684\u65b9\u5f0f\u662f\u628a\u4e00\u4e9b\u503c\u5408\u5728\u4e00\u8d77\uff0c\u653e\u5728\u4e2d\u62ec\u53f7\u91cc\uff0c\u5e76\u7528\u9017\u53f7\u7ed9\u9694\u5f00\uff1a myList = [\"the first value in the list\", 1999, 4.5]\u8fd9\u521b\u5efa\u4e86\u4e00\u4e2a\u5e8f\u5217\uff0c\u540d\u4e3amyList\uff0c\u957f\u5ea6\u4e3a3\u3002\u5e8f\u5217\u7684\u6bcf\u4e00\u9879\u90fd\u6709\u4e00\u4e2a\u540d\u4e3aindex\u7684\u6570\u5b57\u5bf9\u5e94\uff1a\u7b2c\u4e00\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u662f0\uff0c\u4e0b\u4e00\u4e2a\u5143\u7d20\u7d22\u5f15\u662f1\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u5355\u4e2a\u7684\u53d8\u91cf\u7531\u5e8f\u5217\u6784\u6210\uff0c\u540d\u5b57\u662f \u00ablistName\u00bb[\u00abindexNumber\u00bb] \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cmyList[0]\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u53d8\u91cf\u7684\u503c\u662f\u5b57\u7b26\u4e32\"the first value in the list\"\u548cprint(myList[2]) would print 4.5\u3002\u4f60\u4e5f\u53ef\u4ee5\u6539\u53d8\u5e8f\u5217\u4e2d\u6bcf\u4e00\u9879\u7684\u503c\uff0c\u5e76\u5c06\u6574\u4e2a\u5e8f\u5217\u6253\u5370\u51fa\u6765\uff1a Example\u66f4\u65b0\u5e76\u6253\u5370\u5e8f\u5217\u3002 numbers = ['zero', 'one', 'two'] numbers[0] = 'zilch' print(numbers) \u6b63\u5982\u4f60\u6240\u770b\u5230\u7684\u90a3\u6837\uff0cnumbers[0]\u88ab\u5f53\u4f5c\u6210\u4e00\u4e2a\u53d8\u91cf\uff1a\u62e5\u6709\u4e00\u4e2a\u503c\uff0c\u8fd9\u4e2a\u503c\u4e5f\u53ef\u4ee5\u6539\u53d8\u3002 \u63a5\u4e0b\u6765\uff0c\u5c1d\u8bd5\u9884\u6d4b\u4e0b\u5217\u4f8b\u5b50\u7684\u6700\u540e\u72b6\u6001\uff0c\u7136\u540e\u4e0e\u5b9e\u9645\u60c5\u51b5\u6bd4\u5bf9\u3002 Multiple Choice &hellip; <a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/zh-13\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-9301","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/9301","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/comments?post=9301"}],"version-history":[{"count":9,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/9301\/revisions"}],"predecessor-version":[{"id":10231,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/9301\/revisions\/10231"}],"wp:attachment":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/media?parent=9301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}