{"id":9297,"date":"2016-06-07T23:29:59","date_gmt":"2016-06-08T03:29:59","guid":{"rendered":"http:\/\/cscircles.cemc.uwaterloo.ca\/?page_id=9297"},"modified":"2017-06-28T18:35:27","modified_gmt":"2017-06-28T22:35:27","slug":"zh-11a","status":"publish","type":"page","link":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/zh-11a\/","title":{"rendered":"11A: \u5c0f\u5199"},"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><em>\u7b2c11\u8bfe\u6709\u4e09\u4e2a\u90e8\u5206A, B, C\uff0c\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u5b66\u4e60\u3002<\/em><\/p>\n<p>\u8fd9\u8282\u8bfe\u5305\u62ec\u4e00\u4e2a\u7ec3\u4e60\uff0c\u4f60\u9700\u8981\u5199\u4e24\u4e2a\u51fd\u6570\uff1a\u4e00\u4e2a\u4f1a\u5229\u7528\u53e6\u4e00\u4e2a\u6765\u5b8c\u6210\u6700\u7ec8\u76ee\u7684\u3002\u6700\u7ec8\u76ee\u7684\u662f\u5199\u4e00\u4e2a\u51fd\u6570<code>lowerString<\/code>\uff0c\u4f7f\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u7684\u5b57\u6bcd\u90fd\u8f6c\u6362\u6210<em>\u5c0f\u5199<\/em>\uff08A, B, C\u662f<em>\u5927\u5199<\/em>\u5b57\u6bcd\uff0ca, b, c\u662f<em>\u5c0f\u5199<\/em>\uff09\u3002\u6bd4\u5982\uff0c<\/p>\n<pre>lowerString(\"This string has 9 CAPITAL letters (&amp; Punctuation)!\")<\/pre>\u5c31\u5e94\u8be5\u662f<\/p>\n<pre>\"this string has 9 capital letters (&amp; punctuation)!\"<\/pre>\n<h2>\u7b2c1\u6b65\uff1a\u5b57\u7b26<\/h2>\n<p>\u7b2c\u4e00\u6b65\u662f\u7f16\u5199\u4e00\u4e2a\u51fd\u6570<code>lowerChar(char)<\/code>\u3002\u8fd4\u8fd8\u4e00\u4e2a\u5b57\u7b26<code>char<\/code>\u8f6c\u6362\u6210\u5c0f\u5199\u540e\u7684\u503c\u3002\u8be5\u7a0b\u5e8f\u5e94\u8be5\u505a\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u8f93\u5165\u7684\u5b57\u7b26<code>char<\/code>\u662f\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\uff08\u5728'<code>A<\/code>'\u548c'<code>Z<\/code>'\u4e4b\u95f4\uff09\uff0c\u51fd\u6570\u5219\u8fd4\u8fd8\u8be5\u5b57\u6bcd\u7684\u5c0f\u5199\u5f62\u5f0f\uff08\u5728'<code>a<\/code>'\u548c'<code>z<\/code>'\u4e4b\u95f4\uff09<\/li>\n<li>\u82e5\u662f\u5176\u4ed6\u60c5\u51b5\uff0c\u51fd\u6570\u5219\u8fd4\u8fd8\u4e0e<code>char<\/code>\u76f8\u540c\u7684\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<p>\uff08\u4e3a\u4e86\u5b8c\u6210\u7b2c\u4e00\u6b65\uff0c\u4f60\u4f1a\u7528\u5230<a href=\"\/6-if\/\"><code>if<\/code> statement<\/a>, \u4e00\u4e2a <a href=\"\/9-else-and-or-not\/\"><code>and<\/code>\u8fd0\u7b97\u7b26<\/a>, \u4ee5\u53ca\u4e00\u4e9b\u4ece<a href=\"\/7a-strings\/\">\u5b57\u7b26\u4e32\u8bfe\u7a0b\u4e2d\u5b66\u5230\u7684\u77e5\u8bc6<\/a>\u3002)<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform0\" method=\"POST\">\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'>Coding Exercise: <\/span><span class='title'>\u5c0f\u5199\u5b57\u7b26<\/span><\/div>\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<code>lowerChar(char)<\/code>\uff0c\u8fd9\u4e2a\u51fd\u6570\u6ee1\u8db3\u4ee5\u4e0a\u63cf\u8ff0\u7684\u6761\u4ef6<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='usercode0' id='usercode0'  cols=10 rows=20   class='pyboxCode RW'>\n<\/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,'Y')\" ><\/td>\n<td><input type='button' name='history' value=\"History\" onclick=\"historyClick(0,'11a.lowerchar')\" ><\/td>\n<\/tr><\/table><select id='pbSelect0' class='selectmore'><option name='more'>More actions...<\/option>\n<option name='help' data-pbonclick=\"helpClick(0);\" >Help<\/option>\n<\/select><\/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=\"04ff90b966ca25496ea19790bd59d187\"\/>\n<div id='pbresults0' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(0);});document.getElementById(\"submit0\").value = \"Run program\";document.getElementById(\"inputInUse0\").value = \"N\";<\/script>\n<\/p>\n<h2>\u7b2c\u4e8c\u6b65: \u5b57\u7b26\u4e32<\/h2>\n<p>\u73b0\u5728\uff0c\u4f60\u9700\u8981\u7f16\u5199\u7b2c\u4e8c\u4e2a\u51fd\u6570 <code>lowerString(string)<\/code> \uff0c\u5b83\u5c06\u4f1a\u8fd4\u8fd8\u6574\u4e2a\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5c0f\u5199\u7684\u7ed3\u679c\u3002\u4f60\u9700\u8981\u8c03\u7528<code>lowerChar<\/code> \uff0c\u5e76\u5c06\u5176\u5bf9\u6bcf\u4e2a\u5b57\u7b26\u4f7f\u7528\u3002\u6211\u4eec\u5efa\u8bae\u4f60\u6309\u4e0b\u9762\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u5c06\u4f60\u7b54\u6848\u4e2dlowChar(char)\u7684\u5b9a\u4e49\u590d\u5236\u5230\u7b2c\u4e00\u90e8\u5206\u3002<\/li>\n<li>\u7136\u540e\u5b9a\u4e49\u7b2c\u4e8c\u4e2a\u51fd\u6570,<code>lowerString(string)<\/code>\n<ul>\n<li>\u5728lowerString\u4e2d\u7684\u7b2c\u4e00\u884c\u5b9a\u4e49\u4e00\u4e2a\u65b0\u7684\u53d8\u91cf <code>result = \"\"<\/code> \uff0c\u4f7f\u5b83\u7b49\u4e8e\u7a7a\u767d\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n<li>\u4f7f\u7528\u4e00\u4e2a<a href=\"\/7c-loops\/\">for loop\uff08\u5faa\u73af\uff09<\/a>\u548c<code>i<\/code>\uff0c\u5e76\u8bbe<code>result = result + lowerChar(string[i])<\/code><\/li>\n<li>\u6700\u540e\uff0c<code>return result<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform1\" method=\"POST\">\n<div class='pybox modeNeutral ' id='pybox1'>\n<img title='You have not yet completed this problem.' src='https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-content\/plugins\/pybox\/files\/icon.png' class='pycheck'\/><div class=\"heading\"><span class='type'>Coding Exercise: <\/span><span class='title'>\u5c0f\u5199\u5b57\u7b26\u4e32<\/span><\/div>\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570<code>lowerString(string)<\/code>\uff0c\u5b83\u5c06\u8fd4\u8fd8<code>string<\/code>\u8f6c\u6362\u5230\u5c0f\u5199\u7684\u7ed3\u679c\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='usercode1' id='usercode1'  cols=10 rows=20   class='pyboxCode RW'>\n# \u9996\u5148, \u590d\u5236\u4f60\u7684 lowerChar() \u5b9a\u4e49\u5230\u8fd9\u91cc\n# \u63a5\u7740\u5b9a\u4e49lowerString(string)\n<\/textarea><\/div>\n<div id='pbhistory1' class='flexcontain' style='display:none;'><\/div>\n<input type='hidden' id='defaultCode1' value='# \\u9996\\u5148, \\u590d\\u5236\\u4f60\\u7684 lowerChar() \\u5b9a\\u4e49\\u5230\\u8fd9\\u91cc\\n# \\u63a5\\u7740\\u5b9a\\u4e49lowerString(string)\\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='consolecopy' value=\"Open in console\" onclick=\"pbConsoleCopy(1)\" ><\/td>\n<td><input type='button' name='visualize' value=\"Visualize\" onclick=\"pbVisualize(1,'Y')\" ><\/td>\n<td><input type='button' name='history' value=\"History\" onclick=\"historyClick(1,'11a.lowerstring')\" ><\/td>\n<\/tr><\/table><select id='pbSelect1' class='selectmore'><option name='more'>More actions...<\/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=\"60a987acbefa4a7650d6758590c6216b\"\/>\n<div id='pbresults1' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(1);});document.getElementById(\"submit1\").value = \"Run program\";document.getElementById(\"inputInUse1\").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> \u5728\u63a5\u4e0b\u6765\u7684\u5b66\u4e60\u4e2d, \u4f60\u4f1a\u5b66\u5230\u4f7f\u7528<code>string.lower()<\/code>\u7684\u65b9\u6cd5, \u5b83\u662f\u4e00\u4e2a\u7528\u6765\u5b8c\u6210\u8fd9\u4e9b\u5de5\u4f5c\u7684\u5185\u7f6e\u7684\u65b9\u6cd5\u3002 <\/span><\/td><\/table><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c11\u8bfe\u6709\u4e09\u4e2a\u90e8\u5206A, B, C\uff0c\u53ef\u4ee5\u4ee5\u4efb\u4f55\u987a\u5e8f\u5b66\u4e60\u3002 \u8fd9\u8282\u8bfe\u5305\u62ec\u4e00\u4e2a\u7ec3\u4e60\uff0c\u4f60\u9700\u8981\u5199\u4e24\u4e2a\u51fd\u6570\uff1a\u4e00\u4e2a\u4f1a\u5229\u7528\u53e6\u4e00\u4e2a\u6765\u5b8c\u6210\u6700\u7ec8\u76ee\u7684\u3002\u6700\u7ec8\u76ee\u7684\u662f\u5199\u4e00\u4e2a\u51fd\u6570lowerString\uff0c\u4f7f\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u7684\u5b57\u6bcd\u90fd\u8f6c\u6362\u6210\u5c0f\u5199\uff08A, B, C\u662f\u5927\u5199\u5b57\u6bcd\uff0ca, b, c\u662f\u5c0f\u5199\uff09\u3002\u6bd4\u5982\uff0c lowerString(\"This string has 9 CAPITAL letters (&amp; Punctuation)!\")\u5c31\u5e94\u8be5\u662f \"this string has 9 capital letters (&amp; punctuation)!\" \u7b2c1\u6b65\uff1a\u5b57\u7b26 \u7b2c\u4e00\u6b65\u662f\u7f16\u5199\u4e00\u4e2a\u51fd\u6570lowerChar(char)\u3002\u8fd4\u8fd8\u4e00\u4e2a\u5b57\u7b26char\u8f6c\u6362\u6210\u5c0f\u5199\u540e\u7684\u503c\u3002\u8be5\u7a0b\u5e8f\u5e94\u8be5\u505a\u5982\u4e0b\u5185\u5bb9\uff1a \u5982\u679c\u8f93\u5165\u7684\u5b57\u7b26char\u662f\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\uff08\u5728'A'\u548c'Z'\u4e4b\u95f4\uff09\uff0c\u51fd\u6570\u5219\u8fd4\u8fd8\u8be5\u5b57\u6bcd\u7684\u5c0f\u5199\u5f62\u5f0f\uff08\u5728'a'\u548c'z'\u4e4b\u95f4\uff09 \u82e5\u662f\u5176\u4ed6\u60c5\u51b5\uff0c\u51fd\u6570\u5219\u8fd4\u8fd8\u4e0echar\u76f8\u540c\u7684\u7ed3\u679c\u3002 \uff08\u4e3a\u4e86\u5b8c\u6210\u7b2c\u4e00\u6b65\uff0c\u4f60\u4f1a\u7528\u5230if statement, \u4e00\u4e2a and\u8fd0\u7b97\u7b26, \u4ee5\u53ca\u4e00\u4e9b\u4ece\u5b57\u7b26\u4e32\u8bfe\u7a0b\u4e2d\u5b66\u5230\u7684\u77e5\u8bc6\u3002) Coding Exercise: \u5c0f\u5199\u5b57\u7b26\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570lowerChar(char)\uff0c\u8fd9\u4e2a\u51fd\u6570\u6ee1\u8db3\u4ee5\u4e0a\u63cf\u8ff0\u7684\u6761\u4ef6You need to create an &hellip; <a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/zh-11a\/\">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-9297","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/9297","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=9297"}],"version-history":[{"count":8,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/9297\/revisions"}],"predecessor-version":[{"id":10225,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/9297\/revisions\/10225"}],"wp:attachment":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/media?parent=9297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}