{"id":109,"date":"2016-05-09T15:11:38","date_gmt":"2016-05-09T13:11:38","guid":{"rendered":"http:\/\/www.tastestars.com\/?p=109"},"modified":"2016-05-09T15:11:38","modified_gmt":"2016-05-09T13:11:38","slug":"python4","status":"publish","type":"post","link":"https:\/\/tastestars.com\/index.php\/2016\/05\/09\/python4\/","title":{"rendered":"Python\u2014\u2014\u53e6\u5916\u51e0\u4e2a\u53ef\u7231\u7684\u5c0f\u7a0b\u5e8f"},"content":{"rendered":"<h1>\n\t<span style=\"font-size:12px;font-weight:normal;line-height:1.5;\">\u4e00\u5468\u6ca1\u6709\u5b66\u4e60Python\uff0c\u53d1\u73b0\u6709\u70b9\u5fd8\u8bb0\u4e86\uff0c\u770b\u535a\u5ba2\u5f88\u5feb\u5c31\u56de\u5fc6\u8d77\u6765\u5b66\u7684\u5c11\u7684\u53ef\u601c\u7684\u77e5\u8bc6\u4e86\u3002\u6240\u4ee5\u535a\u5ba2\u662f\u4e2a\u597d\u4e1c\u897f\uff0c\u5e2e\u52a9\u6211\u4eec\u5efa\u7acb\u66f4\u8301\u58ee\u7684\u7a81\u89e6\u3002<\/span><br \/>\n<\/h1>\n<h2>\n\t\u5c0f\u7a0b\u5e8f\uff1a\u6444\u6c0f\u5ea6\u7684\u8f6c\u6362\uff1a<br \/>\n<\/h2>\n<p>\n\t\u5199\u7a0b\u5e8f\u7684\u65f6\u5019\u603b\u6709\u62a5\u9519\uff1a\u201cTypeError: cannot concatenate &#8216;str&#8217; and &#8216;float&#8217; objects\u201d\u3002\u56e0\u4e3a\u8fd9\u4e2aPython2\u5440\u6bd4\u8f83\u8f74\uff0c\u5b83\u8ba4\u4e3a\u201c+\u201d\u7684\u610f\u4e49\u8981\u4e48\u5c31\u662f\u52a0\u51cf\u4e58\u9664\u91cc\u7684\u52a0\u53f7\uff0c\u8981\u4e48\u5c31\u662f\u76f8\u540c\u53d8\u91cf\u7684\u8fde\u63a5\u3002\u6240\u4ee5\uff0c\n<\/p>\n<pre>number=raw_input(number)\r\nprint(\"number=\"+number)<\/pre>\n<p>\n\t\u8fd9\u6837\u7684\u8bed\u53e5\u770b\u8d77\u6765\u5bf9\u4e8ejava\uff0cc\u4ec0\u4e48\u7684\u903b\u8f91\u662f\u975e\u5e38\u6b63\u5e38\uff0c\u4f46\u662f\u5bf9\u4e8ePython2\u5c31\u4e0d\u5bf9\u4e86\uff0cnumber\u662f\u4e2a\u6570\u5b57\uff08\u53ef\u80fd\u662fint\u6216\u8005float\uff09\u4f60\u600e\u4e48\u80fd\u548c\u5b57\u7b26\u4e32\u8fde\u5728\u4e00\u8d77\u5462\uff1f\u89e3\u51b3\u65b9\u6cd5\u5c31\u662f\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u5566\u3002\n<\/p>\n<h4>\n\t\u8981\u6c42\uff1a<strong>Write a function called celsius(f) that could translate degrees fahrenheit into degrees celsius.<\/strong><br \/>\n<\/h4>\n<h4>\n\tcode\uff1a<br \/>\n<\/h4>\n<pre>#!\/usr\/bin\/env python\r\n# -*- coding: utf-8 -*-\r\nf = raw_input(\"Please input the degrees fahrenheit\")\r\nt = (float(f) - 32.0 ) \/ 1.8\r\nprint(\"The degrees celsius is \" + str(t))<\/pre>\n<h4>\n\t\u8f93\u51fa\uff1a<br \/>\n<\/h4>\n<pre>C:\\Users\\Administrator\\Desktop&gt;py 3.1.py\r\nPlease input the degrees fahrenheit: 35.6\r\nThe degrees celsius is 2.0<\/pre>\n<h2>\n\t\u5c0f\u7a0b\u5e8f\uff1a\u6bd4\u8f83\u51fd\u6570cmp\uff08\uff09<br \/>\n<\/h2>\n<h4>\n\t\u8981\u6c42\uff1a<br \/>\n<\/h4>\n<pre>Write a function called maximum(x,y) that returns the biggest of the two parameters x and y.\r\nTest this function with a call like maximum(\"hej\",\"ha\"). What's the result?<\/pre>\n<p>\n\t\u95ee\u9898\u60f3\u5f53\u7b80\u5355\uff0c\u4e0d\u8fc7\u9898\u76ee\u6709\u70b9\u6b67\u4e49\uff0c\u662f\u4e24\u4e2a\u6570\u5b57\u7684\u6bd4\u8f83\uff1f\u8fd8\u662f\u5b57\u7b26\u4e32\u7684\u6bd4\u8f83?\u4e0d\u8fc7\u8fd8\u662f\u6709\u70b9\u6536\u83b7\n<\/p>\n<ul>\n<li>\n\t\t\u51fd\u6570\u5b9e\u73b0\u9700\u8981\u5199\u5728\u8c03\u7528\u524d\u9762\n\t<\/li>\n<li>\n\t\t\u51fd\u6570cmp\uff08x,y\uff09\u662f\u6309\u7167\u5b57\u5178\u6392\u5e8f\u6bd4\u8f83\u5927\u5c0f\u7684\n\t<\/li>\n<li>\n\t\t\u76f4\u63a5\u6bd4\u8f83if\uff08x&gt;y\uff09\u4e5f\u662f\u6309\u7167\u5b57\u5178\u5e8f\u6392\u5e8f\u7684\n\t<\/li>\n<li>\n\t\t\u5982\u679c\u60f3\u8981\u6bd4\u8f83\u6570\u5b57\uff0c\u7528if((int)x&gt;(int)y)\u5c31\u597d\n\t<\/li>\n<\/ul>\n<h4>\n\tcode\uff1a<br \/>\n<\/h4>\n<pre>#!\/usr\/bin\/python\r\n# -*- coding: UTF-8 -*-\r\ndef maximum1(x,y):   #\u5b57\u7b26\u4e32\u6bd4\u8f83\r\n    if(cmp(x,y)):   #\u6216\u8005\u4e5f\u53ef\u4ee5\u76f4\u63a5\u6bd4\u8f83x&gt;y\r\n        return str(y)\r\n    else:\r\n        return str(x)\r\ndef maximum2(x,y):  #\u6570\u5b57\u6bd4\u8f83\r\nif(int(x)&gt;int(y)):\r\n    return str(x)\r\nelse:\r\n    return str(y)\r\n\r\nx=raw_input(\"Input the first number: \")\r\ny=raw_input(\"Input the sencond number: \")\r\nprint(\"The biggest parameter is \"+ maximum1(x,y))\r\nprint(\"The biggest parameter is \"+ maximum2(x,y)) #\u8fd9\u4e2a\u5982\u679c\u8f93\u5165\u7684\u662f\u5b57\u7b26\u4e32\uff0c\u4f1a\u62a5\u9519<\/pre>\n<h4>\n\t\u8f93\u51fa\uff1a<br \/>\n<\/h4>\n<pre>C:\\Users\\Administrator\\Desktop&gt;py 4.1.py\r\nInput the first parameter: hej\r\nInput the second parameter: ha\r\nThe biggest number is ha<\/pre>\n<p>\n\t\u4f46\u662f\u5982\u679c\u7528maximum1\u8f93\u51fa\u4e24\u4e2a\u6570\u5b57\uff1a\n<\/p>\n<pre>C:\\Users\\Administrator\\Desktop&gt;py 4.1.py\r\nInput the first parameter: 473\r\nInput the second parameter: 72\r\nThe biggest parameter is 72<\/pre>\n<p>\n\t\u4e0d\u8981\u95ee\u6211\u4e3a\u4ec0\u4e48\uff0c\u56e0\u4e3a\u5b57\u5178\u6392\u5e8f\u5440~<br \/>\n\u5982\u679c\u7528muximum2\u8f93\u51fa\u8fd9\u4e24\u4e2a\u6570\u5b57\uff0c\u7ed3\u679c\u5c31\u4e0d\u4e00\u6837\u4e86\n<\/p>\n<pre>The biggest number is 473<\/pre>\n<h2>\n\t\u5c0f\u7a0b\u5e8f\uff1a\u4f7f\u7528\u6570\u7ec4list<br \/>\n<\/h2>\n<p>\n\t\u5728python\u4e2d\uff0c\u6570\u7ec4\u7684\u5b9e\u73b0\uff0c\u662f\u7528list\u7684\uff0c\u53ef\u4ee5\u5728\u7f51\u4e0a\u8f7b\u677e\u7684\u627e\u5230\u5404\u79cdlist\u7684\u64cd\u4f5c\u65b9\u6cd5\u3002\u5c31\u4e0d\u8bf4\u5566\u3002\n<\/p>\n<h4>\n\t\u8981\u6c42\uff1a<br \/>\n<\/h4>\n<pre>Write a function printlarge(v) that will print out all the elements within the array v, which is larger than 1 000 000.<\/pre>\n<h4>\n\tcode:<br \/>\n<\/h4>\n<pre>#!\/usr\/bin\/env python\r\n# -*- coding: utf-8 -*-\r\nnum=1\r\nv=list()\r\nwhile(num!=\"0\"):\r\n    num=raw_input(\"input the number in array(input 0 if you want to finish)\")\r\n    v.append(num)\r\nprint(\"output of the array: \")\r\nprint(v)<\/pre>\n<h4>\n\tresult\uff1a<br \/>\n<\/h4>\n<pre>C:\\Users\\Administrator\\Desktop&gt;py 6.1.py\r\ninput the number in array(input 0 if you want to finish)1000000\r\ninput the number in array(input 0 if you want to finish)1000000\r\ninput the number in array(input 0 if you want to finish)2000000\r\ninput the number in array(input 0 if you want to finish)0\r\noutput of the array:\r\n['1000000', '1000000', '2000000', '0']<\/pre>\n<p>\n\t\u8fd9\u4e9b\u90fd\u662f\u975e\u5e38\u7b80\u5355\u7684\u64cd\u4f5c\uff0c\u5199\u8d77\u6765\u8fd8\u633a\u9ebb\u70e6\u7684\uff0c\u4e0d\u8fc7\u4ee5\u540e\u5fd8\u4e86\u518d\u56de\u5fc6\u8d77\u6765\u80af\u5b9a\u6709\u5e2e\u52a9\u7684\u5427~\u53bb\u533b\u52a1\u5ba4\u770b\u4e86\u811a\uff0c\u7ed1\u4e86\u5f88\u53ef\u7231\u7684\u7ef7\u5e26\uff0c\u7136\u540e\uff01\u660e\u5929\u8981\u89c1\u8001\u5e08\uff01\uff01\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u5468\u6ca1\u6709\u5b66\u4e60Python\uff0c\u53d1\u73b0\u6709\u70b9\u5fd8\u8bb0\u4e86\uff0c\u770b\u535a\u5ba2\u5f88\u5feb\u5c31\u56de\u5fc6\u8d77\u6765\u5b66\u7684\u5c11\u7684\u53ef\u601c\u7684\u77e5\u8bc6\u4e86\u3002\u6240\u4ee5\u535a\u5ba2\u662f\u4e2a\u597d\u4e1c\u897f\uff0c\u5e2e\u52a9\u6211 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1,3],"tags":[22,6],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-python","category-studynote","tag-list","tag-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s9Hs6X-python4","_links":{"self":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":1,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/posts\/109\/revisions\/110"}],"wp:attachment":[{"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tastestars.com\/index.php\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}