{"id":9227,"date":"2016-05-29T12:24:53","date_gmt":"2016-05-29T16:24:53","guid":{"rendered":"http:\/\/cscircles.cemc.uwaterloo.ca\/?page_id=9227"},"modified":"2017-06-28T15:08:51","modified_gmt":"2017-06-28T19:08:51","slug":"zh-4","status":"publish","type":"page","link":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/zh-4\/","title":{"rendered":"4: \u7c7b\u578b"},"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>\u4ece\u8fd9\u8282\u8bfe\u5f00\u59cb\uff0c\u793a\u4f8b\u548c\u4ee3\u7801\u8f93\u5165\u6846\u5c06\u4f1a\u6709<\/em> <strong>\u6253\u5f00\u63a7\u5236\u53f0<\/strong> <em>\u548c<\/em> <strong>\u53ef\u89c1\u5316<\/strong>\u8fd9\u4e24\u4e2a\u6309\u94ae\u3002<em>\u4f7f\u7528\u5b83\u4eec\u6765\u5e2e\u52a9\u4f60\u8c03\u8bd5\u548c\u63a2\u7d22\u4ee3\u7801\u3002<\/em><\/p>\n<p>\u5728<a href=\"\/\">Hello, World! \u7a0b\u5e8f\u4e2d<\/a> \u6211\u4eec\u770b\u5230Python\u53ef\u4ee5\u91cd\u590d\u4e00\u53e5\u8bdd\u5e76\u8fd4\u8fd8\u7ed9\u6211\u4eec\u3002\u6211\u4eec\u540c\u6837\u89c1\u5230\u4e86\u51e0\u4e2a\u6570\u5b57\u8fd0\u7b97\u7684\u4f8b\u5b50\u3002\u6570\u5b57\u548c\u53e5\u5b50\u4ece\u6839\u672c\u4e0a\u6765\u8bf4\u662f\u4e0d\u540c\u7684\u5bf9\u8c61\uff0c\u5f53\u4f60\u8bd5\u56fe\u628a\u5b83\u4eec\u6df7\u6dc6\u5728\u4e00\u8d77\u65f6\uff0cPython\u5c31\u4f1a\u51fa\u9519\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>\u8bd5\u56fe\u6bd4\u8f83\u4e00\u4e2a\u5b57\u7b26\u4e32\u548c\u4e00\u4e2a\u6570\u5b57\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'>\nx = \"Hello, World!\"\ny = 35\nz = max(x, y)<\/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=\"be6e76a12e6524cb283e5659895e5c2f\"\/>\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>\u4f60\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u4eec\u6536\u5230\u4e86\u4e00\u4e2a\u9519\u8bef\u6d88\u606f\uff0c<code>max<\/code> \u7684\u4e24\u4e2a\u5b9e\u53c2\u4e0d\u662f\u540c\u4e00\u79cd\u7c7b\u578b\u3002\u8fd9\u4e2a\u9519\u8bef\u6d88\u606f\u7ed9\u6211\u4eec\u63a5\u4e0b\u6765\u5b66\u4e60\u7684\u5185\u5bb9\u505a\u4e86\u4e00\u4e2a\u5f88\u597d\u7684\u5f00\u5934\uff1a<\/p>\n<ul>\n<li><code>\"Hello, World!\"<\/code>\u662f\u4e00\u4e2a<strong>\u5b57\u7b26\u4e32<\/strong>\uff0c\u5728Python\u4e2d\u662f\u4ee5<code>str<\/code>\u663e\u793a\u7684\u3002\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u4e00\u4e2a\u5305\u542b\u6570\u5b57\u3001\u5b57\u6bcd\u548c\u7b26\u53f7\u7684\u5e8f\u5217\uff1b\u6211\u4eec\u5c06\u4f1a\u57287A\u8bfe\u7a0b\u4e2d\u6df1\u5165\u7684\u4e86\u89e3\u5b83\u4eec\u3002<\/li>\n<li><code>35<\/code>\u662f\u4e00\u4e2a<strong>\u6574\u6570<\/strong>\u503c\uff0c\u5728Python\u4e2d\u662f\u4ee5<code>int<\/code>\u663e\u793a\u7684\u3002\u4e00\u4e2a\u6574\u6570\u5c31\u610f\u5473\u7740<em>\u6574\u4e2a\u7684\u6570\u5b57<\/em>\uff1b\u4f8b\u5982\uff0c42\uff0c-12\u548c0\u90fd\u662f\u6574\u6570\u3002<\/li>\n<\/ul>\n<p>\u5728\u7f16\u7a0b\u4e2d\uff0c\u4f7f\u7528\u4e0d\u6b63\u786e\u7684\u5bf9\u8c61 \u7c7b\u578b\u662f\u5bfc\u81f4\u9519\u8bef\u7684\u4e00\u4e2a\u5e38\u89c1\u539f\u56e0\u3002\u8fd9\u5c31\u50cf\u4f60\u8bd5\u56fe\u559d\u4e00\u4e2a\u4e09\u660e\u6cbb\uff1a\u4f60\u5e76\u4e0d\u80fd\u505a\u5230\uff0c\u56e0\u4e3a\u4f60\u53ea\u80fd\u559d\u6db2\u4f53\uff0c\u4f46\u4e09\u660e\u6cbb\u662f\u4e00\u4e2a\u56fa\u4f53\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u8c03\u7528<code>type<\/code>\u51fd\u6570\u6765\u786e\u5b9a\u4e00\u4e2a\u5bf9\u8c61\u7684\u7c7b\u578b\u3002<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform1\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox1'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>\u4e00\u4e9btype\u51fd\u6570\u7684\u4f8b\u5b50\u3002<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 84px;'><textarea wrap='off' name='usercode1' id='usercode1'  cols=10 rows=3 readonly='readonly'  style = 'height : 84px;'  class='pyboxCode RO'>\nprint(type(\"Hello, World!\"))\nprint(type(34))\nprint(type(1.234))<\/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=\"768daed3b2e69c5cd5bc93ea45e1fc32\"\/>\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<p>(<code>class<\/code>\uff08\u7c7b\uff09\u548c<code>type<\/code>\uff08\u7c7b\u578b\uff09\u7684\u610f\u4e49\u76f8\u4f3c\u3002) \u4e0a\u9762\u7684\u51e0\u4e2a\u4f8b\u5b50\u8be0\u91ca\u4e86\u6570\u5b57\u4e2d\u7684\u4e24\u79cd\u4e0d\u540c\u7c7b\u578b\uff0c\u6211\u4eec\u524d\u9762\u63d0\u5230\u7684<code>int<\/code>\u548c\u7528\u6765\u5b58\u50a8\u5341\u8fdb\u5236\u6570\u7684<code>float<\/code>\uff08\u6d6e\u70b9\u6570\uff09\u3002\u4f60\u53ef\u4ee5\u5c06<code>float<\/code>\u7406\u89e3\u4e3a\u4e0d\u7cbe\u786e\u6216\u8fd1\u4f3c\u503c\uff08\u6211\u4eec\u5c06\u4f1a\u57287B\u4e2d\u8be6\u7ec6\u89e3\u91ca\uff09\u3002\u4f60\u53ef\u4ee5\u6df7\u5408<code>float<\/code>\u503c\u548c<code>int<\/code>\u503c\uff0c\u4ed6\u4eec\u6df7\u5408\u7684\u7ed3\u679c\u4f1a\u662f\u4e00\u4e2a\u65b0\u7684<code>float<\/code>\u3002<\/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>\u6df7\u5408\u4e00\u4e2a<code>int<\/code>\u548c<code>float<\/code>\u3002<div class='pyboxTextwrap pyboxCodewrap RO '  style='height: 136px;'><textarea wrap='off' name='usercode2' id='usercode2'  cols=10 rows=5 readonly='readonly'  style = 'height : 136px;'  class='pyboxCode RO'>\nx = 1.2\ny = 2\nz = x * y\nprint(x, y, z)\nprint(type(x), type(y), type(z))<\/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=\"6f21ee769bd3e22ec989fbb8a69edbf5\"\/>\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>\u4e8b\u5b9e\u4e0a\uff0cPython\u5728\u78b0\u5230\u6df7\u5408\u4e00\u4e2a<code>float<\/code>\u548c<code>int<\/code>\u7684\u60c5\u51b5\u65f6\uff0c\u4f1a\u81ea\u52a8\u5c06<code>int<\/code>\u8f6c\u6362\u6210<code>float<\/code>\uff0c\u7136\u540e\u7528\u4e24\u4e2a<code>float<\/code>\u503c\u8fd0\u884c\u540e\u9762\u7684\u7a0b\u5e8f\u3002<\/p>\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'>Multiple Choice Exercise: <\/span><span class='title'>\u6d6e\u70b9<\/span><\/div><div>\u5982\u679c\u6211\u4eec\u5728\u4e0a\u9762\u7684\u7a0b\u5e8f\u4e2d\u5c06<code>1.2<\/code>\u6539\u53d8\u4e3a<code>1.5<\/code>\uff0c\u7b2c\u4e00\u884c\u8f93\u51fa\u4f1a\u662f\u4ec0\u4e48\uff1f<\/div><label>Your choice: <\/label><select id=\"pyselect3\"><option value=\"d\" selected>Select one<\/option><option value=\"w\">1.5 2 3<\/option><option value=\"r\">1.5 2 3.0<\/option><option value=\"w\">An \u4ea7\u751f\u9519\u8bef<\/option><option value=\"w\">1.5 2.0 3.0<\/option><\/select><div class='pyboxbuttons'><input type=\"hidden\" name=\"lang\" value=\"\"\/><input type=\"hidden\" name=\"slug\" value=\"4.mixing\"\/><input type='submit' style='margin:5px;' value='Check answer' onClick='pbMultiCheck(3)'\/><\/div><div class=\"pbresults\" id=\"pyMultiResults3\"><\/div><div class=\"epilogue\">\u6b63\u786e\uff01\u6211\u4eec\u5fc5\u987b\u5728\u8fd9\u91cc\u89e3\u91ca\u4e24\u4e2a\u56e0\u7d20\uff0c\u6765\u770b\u4e3a\u4ec0\u4e48<code>z<\/code>\u88ab\u6253\u5370\u4e3a<code>3.0<\/code>\u3002\n\n<ul>\n<ul>\n\n<li>\u8ba1\u7b97<code>x * y<\/code>\u662f\u6df7\u5408\u4e86\u4e00\u4e2a<code>int<\/code>\u548c\u4e00\u4e2a<code>float<\/code>\uff0cPython\u4f1a\u628a\u4ed6\u4eec\u5f53\u6210\u4e24\u4e2a<code>\u6d6e\u70b9\u6570<\/code>\uff0c\u5e76\u8fd4\u8fd8<code>z<\/code> \u4e3a\u4e00\u4e2a<code>\u6d6e\u70b9\u6570<\/code>\u3002<\/li>\n<\/ul>\n<\/ul>\n\n\n<ul>\n<ul>\n<li><code>z<\/code>\u7684\u6570\u5b66\u503c\u662f1.5\u4e58\u4ee52\uff0c\u4e3a3\uff0c\u4f46\u5374\u88ab\u4fdd\u5b58\u4e3a\u4e0d\u51c6\u786e\u7684\u5c0f\u6570\u5f62\u5f0f\u2014\u2014<code>\u6d6e\u70b9\u6570<\/code>\u3002\u5f53Python\u6253\u5370\u4efb\u4f55 <code>\u6d6e\u70b9\u6570<\/code>\u65f6\uff0c\u5373\u4f7f\u5b83\u7684\u503c\u662f\u4e00\u4e2a\u6574\u6570\uff0c\u5b83\u4e5f\u4f1a\u88ab\u6253\u5370\u4e3a\u4ee5<code><code>.0<\/code><\/code>\u7ed3\u5c3e\u6765\u8868\u660e\u5b83\u662f\u4e00\u4e2a\u4e0d\u51c6\u786e\u7684\u503c\u3002<\/li>\n<\/ul>\n<\/ul>\n\n\n\n\u540c\u65f6\uff0c\u8bf7\u8bb0\u4f4f<code>y<\/code>\u7684\u503c\u548c\u7c7b\u578b\u4ece\u672a\u88ab\u6539\u53d8\u3002\n<\/div><\/div>\n<p>\u5728\u7f16\u7a0b\u4e2d\uff0c\u4f60\u4f1a\u7ecf\u5e38\u9700\u8981\u6539\u53d8\u6570\u636e\u7684\u7c7b\u578b\u3002\u5c31\u50cf\u4f60\u53ef\u4ee5\u7528\u6405\u62cc\u673a\u5c06\u4e09\u660e\u6cbb\u4ece\u56fa\u4f53\u8f6c\u53d8\u6210\u6db2\u4f53\u4e00\u6837\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528<strong>\u7c7b\u578b\u8f6c\u6362\u51fd\u6570<\/strong>\u5c06\u6570\u636e\u4ece\u4e00\u79cd\u7c7b\u578b\u8f6c\u6362\u5230\u53e6\u4e00\u79cd\u7c7b\u578b\u3002\u5728\u5199\u76ee\u6807\u7c7b\u578b\u5c31\u50cf\u662f\u5199\u4e00\u4e2a\u8c03\u7528\u51fd\u6570\u7684\u65b9\u7a0b\u4e00\u6837\uff0c\u6bd4\u5982\uff1a<\/p>\n<pre>x = float(\"3.4\")\r\nprint(x-1)<\/pre>\u5c06\u5b57\u7b26\u4e32<code>\"3.4\"<\/code>\u53d8\u6210\u6d6e\u70b9\u6570<code>3.4<\/code>\uff0c\u7136\u540e\u6253\u5370\u51fa<code>2.4<\/code>\u3002\u5982\u679c\u4e0d\u4f7f\u7528\u7c7b\u578b\u8f6c\u6362<a href=\"http:\/\/cscircles.cemc.uwaterloo.ca\/console\/?consolecode=x%3D%223.4%22%0Aprint%28x-1%29\" target=\"_blank\">\u7a0b\u5e8f\u5c31\u4f1a\u5d29\u6e83<\/a>, \u56e0\u4e3a\u5b57\u7b26\u4e32\u51cf\u53bb\u4e00\u4e2a\u6570\u5b57\u4e0d\u7b26\u5408\u903b\u8f91\u3002<\/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> \u6709\u4e9b\u65f6\u5019\uff0cPython<em>\u5141\u8bb8<\/em>\u4f60\u4f7f\u7528\u6570\u5b66\u8fd0\u7b97\u7b26\u53f7\u6df7\u5408\u4e00\u4e2a\u5b57\u7b26\u4e32\u548c\u6570\u5b57\u3002\u8bed\u53e5<code><code>print(\"hots\" * 2)<\/code>\u00a0<\/code>\u4f1a\u6253\u5370\u51fa<code>hotshots<\/code>\u3002Python\u7684\u89c4\u5219\u662f\u5982\u679c\u8ba9\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e58\u4ee5\u4e00\u4e2a\u6574\u6570\uff0c\u90a3\u4e48\u5b83\u7684\u5b9e\u9645\u610f\u4e49\u5c31\u662f\u5728\u8fd9\u4e2a\u5b57\u7b26\u4e32\u540e\u590d\u5236\u76f8\u5e94\u6570\u91cf\u7684\u62f7\u8d1d\u3002\u6211\u4eec\u4f1a\u5728\u540e\u9762\u770b\u5230\u201c\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u52a0\u201d\u5728Python\u4e2d\u4e5f\u662f\u53ef\u884c\u7684\u3002  <\/span><\/td><\/table><\/p>\n<p>\u4e0d\u540c\u7684\u7c7b\u578b\u8f6c\u6362\u4f1a\u6709\u4e0d\u540c\u7684\u8868\u73b0\uff1a<\/p>\n<ul>\n<li>\u5c06<code>\u6d6e\u70b9\u6570<\/code>\u8f6c\u6362\u6210<code>\u6574\u6570<\/code>\u4f1a\u4f7f\u5c0f\u6570\u70b9\u540e\u7684\u4fe1\u606f\u4e22\u5931\uff0c\u4f8b\u5982<code>int(1.234)<\/code>\u4f1a\u8fd4\u8fd8<code>1<\/code>\uff0c<code>int(-34.7)<\/code>\u4f1a\u8fd4\u8fd8<code>-34<\/code>\u3002<\/li>\n<li>\u5982\u679c<code>\u5b57\u7b26\u4e32<\/code>\u7684\u683c\u5f0f\u548c<code>\u6574\u6570<\/code>\u4e0d\u4e00\u6837\uff0c \u90a3\u4e48\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6574\u6570\u4f1a\u9020\u6210\u9519\u8bef\u3002\u4f8b\u5982<a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/console\/?consolecode=x%20%3D%20int%28%221.234%22%29\" target=\"_blank\"><code>int(\"1.234\")<\/code>\u4f1a\u9020\u6210\u9519\u8bef<\/a>\u3002<\/li>\n<li>\u5982\u679c<code>\u5b57\u7b26\u4e32<\/code>\u4e0d\u662f\u4e00\u4e2a\u6570\uff0c\u90a3\u4e48\u5c06\u5176\u8f6c\u6362\u6210<code>\u6d6e\u70b9\u6570<\/code>\u4f1a\u9020\u6210\u9519\u8bef\u3002\u4f8b\u5982<a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/console\/?consolecode=x%20%3D%20float%28%22sandwich%22%29\" target=\"_blank\"><code>float(\"sandwich\")<\/code>\u4f1a\u9020\u6210\u9519\u8bef<\/a>\u3002<\/li>\n<\/ul>\n<p>\u7c7b\u578b\u8f6c\u6362\u7684\u4e00\u4e2a\u5e38\u89c1\u7528\u5904\u662f\u6211\u4eec\u5c06\u4f1a\u770b\u5230\u7684\u8f6c\u6362\u7528\u6237\u8f93\u5165\uff0c\u4ece\u4e00\u4e2a\u5b57\u7b26\u4e32\u8f6c\u6362\u5230\u6570\u5b57\u7c7b\u578b\u3002\u8fd9\u91cc\u662f\u4e00\u4e2a\u5feb\u901f\u7684\u6f14\u793a\u3002<\/p>\n<p><form class=\"pbform\" action=\"#\" id=\"pbform4\" method=\"POST\">\n<div class='pybox modeNeutral  facultative' id='pybox4'>\n<div class=\"heading\"><span class=\"title\">Example<\/span><\/div>\u7c7b\u578b\u8f6c\u6362\u7684\u4f8b\u5b50\u3002<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'>\ninputStr = \"12\"                          # \u7528\u6237\u7684\u4e00\u4e2a\u8f93\u5165\nprint(\"The input type is\", type(inputStr))\nx = int(inputStr)\nprint(x, \"is of type\", type(x), \"and its square is\", x*x)\nprint(inputStr * inputStr)               # \u8fd9\u884c\u4ee3\u7801\u4f1a\u9020\u6210\u4e00\u4e2a\u9519\u8bef<\/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=\"d6929f0f37a96ebb0cb72c2ec536ea76\"\/>\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>\u4e0b\u9762\u662f\u8fd9\u8282\u8bfe\u6700\u540e\u4e00\u4e2a\u7ec3\u4e60\u3002<\/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> \u56e0\u4e3a\u73b0\u5728\u6709\u5f88\u591a\u7684\u7f16\u8f91\u547d\u4ee4\uff0c\u6709\u7684\u5df2\u7ecf\u642c\u8fdb\u6807\u8bb0\u4e3a<strong>\u66f4\u591a\u52a8\u4f5c<\/strong>\u7684\u83dc\u5355\u4e2d\u3002 <\/span><\/td><\/table><\/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'>Tasty Typecasting<\/span><\/div>\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\u6765\u5e2e\u52a9\u5728\u805a\u4f1a\u4e0a\u5582\u9971\u4f60\u7684\u670b\u53cb\u4eec\uff0c\u4f60\u9700\u8981\u5bf9\u4e00\u4e9b<em>\u65b9\u5f62\u62ab\u8428<\/em>\u8fdb\u884c\u4e00\u4e9b\u8ba1\u7b97\u3002\u5047\u8bbe\u6253\u5206\u8f6f\u4ef6\u4f1a\u5b9a\u4e49\u4e00\u4e2a\u53eb\u505a<code>inputStr<\/code>\u7684\u5b57\u7b26\u4e32\u7ed9\u4f60\uff0c\u5b83\u662f\u4e00\u4e2a\u5c0f\u6570\u5b57\u7b26\u4e32\uff0c\u7528\u6765\u8868\u793a\u62ab\u8428\u7684\u8fb9\u957f L (cm)\u3002\u62ab\u8428\u7684\u9762\u79ef<em>A = L*L<\/em>\u3002\u63a5\u7740\u5047\u8bbe\u6bcf\u4e2a\u4eba\u9700\u8981\u5403100cm<sup>2<\/sup>\u7684\u62ab\u8428\uff0c\u8bf7\u8ba1\u7b97\u8fd9\u4e2a\u62ab\u8428\u53ef\u4ee5\u5582\u9971\u591a\u5c11\u4eba\uff0c\u8bf7\u5c06\u7ed3\u679c<em>\u56db\u820d\u4e94\u5165\u81f3\u6700\u63a5\u8fd1\u7684\u6574\u6570<\/em>\u3002<a class=\"hintlink\"  id=\"hintlink6\">Hint<\/a><\/p>\n<div><em>\u4f8b\u5b50<\/em>\uff1a\u5982\u679c<code>inputStr<\/code>\u662f<code>\"17.5\"<\/code>, the \u9762\u79ef\u4f1a\u662f306.25 cm<sup>2<\/sup>, \u6240\u4ee5<code>3<\/code>\u662f\u6b63\u786e\u7684\u8f93\u51fa\u3002<\/div>\n<p><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<\/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,'Y')\" ><\/td>\n<td><input type='button' name='history' value=\"History\" onclick=\"historyClick(5,'4.pizza')\" ><\/td>\n<\/tr><\/table><select id='pbSelect5' class='selectmore'><option name='more'>More actions...<\/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=\"a9ffbb579638836c943821144f643da7\"\/>\n<div id='pbresults5' class='pbresults avoidline'><\/div>\n<\/div>\n<\/form>\n<script type='text\/javascript'>jQuery(function(){pbToggleCodeMirror(5);});document.getElementById(\"submit5\").value = \"Run program\";document.getElementById(\"inputInUse5\").value = \"N\";<\/script>\n<\/p>\n<p>\u5b8c\u6210\u540e\uff0c\u8bf7\u524d\u5f80\u4e0b\u4e00\u8bfe\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u8fd9\u8282\u8bfe\u5f00\u59cb\uff0c\u793a\u4f8b\u548c\u4ee3\u7801\u8f93\u5165\u6846\u5c06\u4f1a\u6709 \u6253\u5f00\u63a7\u5236\u53f0 \u548c \u53ef\u89c1\u5316\u8fd9\u4e24\u4e2a\u6309\u94ae\u3002\u4f7f\u7528\u5b83\u4eec\u6765\u5e2e\u52a9\u4f60\u8c03\u8bd5\u548c\u63a2\u7d22\u4ee3\u7801\u3002 \u5728Hello, World! \u7a0b\u5e8f\u4e2d \u6211\u4eec\u770b\u5230Python\u53ef\u4ee5\u91cd\u590d\u4e00\u53e5\u8bdd\u5e76\u8fd4\u8fd8\u7ed9\u6211\u4eec\u3002\u6211\u4eec\u540c\u6837\u89c1\u5230\u4e86\u51e0\u4e2a\u6570\u5b57\u8fd0\u7b97\u7684\u4f8b\u5b50\u3002\u6570\u5b57\u548c\u53e5\u5b50\u4ece\u6839\u672c\u4e0a\u6765\u8bf4\u662f\u4e0d\u540c\u7684\u5bf9\u8c61\uff0c\u5f53\u4f60\u8bd5\u56fe\u628a\u5b83\u4eec\u6df7\u6dc6\u5728\u4e00\u8d77\u65f6\uff0cPython\u5c31\u4f1a\u51fa\u9519\uff1a Example\u8bd5\u56fe\u6bd4\u8f83\u4e00\u4e2a\u5b57\u7b26\u4e32\u548c\u4e00\u4e2a\u6570\u5b57\u3002 x = \"Hello, World!\" y = 35 z = max(x, y) \u4f60\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u4eec\u6536\u5230\u4e86\u4e00\u4e2a\u9519\u8bef\u6d88\u606f\uff0cmax \u7684\u4e24\u4e2a\u5b9e\u53c2\u4e0d\u662f\u540c\u4e00\u79cd\u7c7b\u578b\u3002\u8fd9\u4e2a\u9519\u8bef\u6d88\u606f\u7ed9\u6211\u4eec\u63a5\u4e0b\u6765\u5b66\u4e60\u7684\u5185\u5bb9\u505a\u4e86\u4e00\u4e2a\u5f88\u597d\u7684\u5f00\u5934\uff1a \"Hello, World!\"\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5728Python\u4e2d\u662f\u4ee5str\u663e\u793a\u7684\u3002\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u4e00\u4e2a\u5305\u542b\u6570\u5b57\u3001\u5b57\u6bcd\u548c\u7b26\u53f7\u7684\u5e8f\u5217\uff1b\u6211\u4eec\u5c06\u4f1a\u57287A\u8bfe\u7a0b\u4e2d\u6df1\u5165\u7684\u4e86\u89e3\u5b83\u4eec\u3002 35\u662f\u4e00\u4e2a\u6574\u6570\u503c\uff0c\u5728Python\u4e2d\u662f\u4ee5int\u663e\u793a\u7684\u3002\u4e00\u4e2a\u6574\u6570\u5c31\u610f\u5473\u7740\u6574\u4e2a\u7684\u6570\u5b57\uff1b\u4f8b\u5982\uff0c42\uff0c-12\u548c0\u90fd\u662f\u6574\u6570\u3002 \u5728\u7f16\u7a0b\u4e2d\uff0c\u4f7f\u7528\u4e0d\u6b63\u786e\u7684\u5bf9\u8c61 \u7c7b\u578b\u662f\u5bfc\u81f4\u9519\u8bef\u7684\u4e00\u4e2a\u5e38\u89c1\u539f\u56e0\u3002\u8fd9\u5c31\u50cf\u4f60\u8bd5\u56fe\u559d\u4e00\u4e2a\u4e09\u660e\u6cbb\uff1a\u4f60\u5e76\u4e0d\u80fd\u505a\u5230\uff0c\u56e0\u4e3a\u4f60\u53ea\u80fd\u559d\u6db2\u4f53\uff0c\u4f46\u4e09\u660e\u6cbb\u662f\u4e00\u4e2a\u56fa\u4f53\u3002 \u4f60\u53ef\u4ee5\u8c03\u7528type\u51fd\u6570\u6765\u786e\u5b9a\u4e00\u4e2a\u5bf9\u8c61\u7684\u7c7b\u578b\u3002 Example\u4e00\u4e9btype\u51fd\u6570\u7684\u4f8b\u5b50\u3002 print(type(\"Hello, World!\")) print(type(34)) print(type(1.234)) (class\uff08\u7c7b\uff09\u548ctype\uff08\u7c7b\u578b\uff09\u7684\u610f\u4e49\u76f8\u4f3c\u3002) \u4e0a\u9762\u7684\u51e0\u4e2a\u4f8b\u5b50\u8be0\u91ca\u4e86\u6570\u5b57\u4e2d\u7684\u4e24\u79cd\u4e0d\u540c\u7c7b\u578b\uff0c\u6211\u4eec\u524d\u9762\u63d0\u5230\u7684int\u548c\u7528\u6765\u5b58\u50a8\u5341\u8fdb\u5236\u6570\u7684float\uff08\u6d6e\u70b9\u6570\uff09\u3002\u4f60\u53ef\u4ee5\u5c06float\u7406\u89e3\u4e3a\u4e0d\u7cbe\u786e\u6216\u8fd1\u4f3c\u503c\uff08\u6211\u4eec\u5c06\u4f1a\u57287B\u4e2d\u8be6\u7ec6\u89e3\u91ca\uff09\u3002\u4f60\u53ef\u4ee5\u6df7\u5408float\u503c\u548cint\u503c\uff0c\u4ed6\u4eec\u6df7\u5408\u7684\u7ed3\u679c\u4f1a\u662f\u4e00\u4e2a\u65b0\u7684float\u3002 Example\u6df7\u5408\u4e00\u4e2aint\u548cfloat\u3002 x = 1.2 y &hellip; <a href=\"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/zh-4\/\">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":"open","template":"","meta":{"footnotes":""},"class_list":["post-9227","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/9227","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=9227"}],"version-history":[{"count":14,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/9227\/revisions"}],"predecessor-version":[{"id":10208,"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/pages\/9227\/revisions\/10208"}],"wp:attachment":[{"href":"https:\/\/cscircles.cemc.uwaterloo.ca\/dev\/wp-json\/wp\/v2\/media?parent=9227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}