{"id":1143,"date":"2024-11-09T19:14:34","date_gmt":"2024-11-09T11:14:34","guid":{"rendered":"https:\/\/gemmartdesign.com\/?p=1143"},"modified":"2024-11-29T22:50:35","modified_gmt":"2024-11-29T14:50:35","slug":"python-post4","status":"publish","type":"post","link":"https:\/\/gemmartdesign.com\/?p=1143","title":{"rendered":"Python\u7df4\u7fd2#4-\u4f7f\u7528def\u8a08\u7b97\u591a\u7d44\u6578\u5b57\u52a0\u7e3d\u8207\u5e73\u65b9\u6839"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u672c\u5468\u76ee\u6a19<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0\u719f\u7df4\u8cc7\u6599\u7d50\u69cb\u7684\u61c9\u7528\uff0c\u4e26\u5b8c\u6210\u4e00\u500b\u7c21\u55ae\u7684\u6587\u5b57\u8655\u7406\u5c08\u6848<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4efb\u52d9<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b78\u7fd2Python\u57fa\u790e\u8a9e\u6cd5\uff08\u8b8a\u6578\u3001\u6578\u64da\u985e\u578b\u3001\u689d\u4ef6\u8a9e\u53e5\u3001\u8ff4\u5708\uff09<\/li>\n\n\n\n<li>\u4f7f\u7528 if \u689d\u4ef6\u63a7\u5236\u548c for \u8ff4\u5708\u4f86\u505a\u7c21\u55ae\u7684\u6578\u5b78\u8a08\u7b97<\/li>\n\n\n\n<li>\u6df1\u5165\u5b78\u7fd2\u5217\u8868\uff08List\uff09\u3001\u5b57\u5178\uff08Dictionary\uff09\u7b49\u8cc7\u6599\u7d50\u69cb<\/li>\n\n\n\n<li>\u5b78\u7fd2\u4f7f\u7528break, continue\u548celse<\/li>\n\n\n\n<li>\u5b78\u7fd2\u4f7f\u7528def\u7a0b\u5f0f\u5340\u584a\u8207\u547c\u53eb\u6307\u4ee4<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5c08\u6848\u7df4\u7fd2<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u8a08\u7b97\u591a\u500b\u6578\u5b57\u7a2e\u548c<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>def caculate(b1,b2):\n    sum=0\n    for b in range(b1,b2+1):\n        sum=sum+b\n    print(sum)\n\ncaculate(0,10)\ncaculate(10,300)\ncaculate(25,30)\ncaculate(5,12)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>55\n45105\n165\n68<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u8a08\u7b97\u591a\u7d44\u5e73\u65b9\u6839<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>def squareroot(a):\n    for a1 in range(a+1):\n        if a1==a**0.5:\n            print(a1)\n            break\n    else:\n        print(\"No value\")\n\nsquareroot(25)\nsquareroot(9)\nsquareroot(37)\nsquareroot(1)\nsquareroot(18)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>5\n3\nNo value\n1\nNo value<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u5468\u76ee\u6a19 \u00a0\u719f\u7df4\u8cc7\u6599\u7d50\u69cb\u7684\u61c9\u7528\uff0c\u4e26\u5b8c\u6210\u4e00\u500b\u7c21\u55ae\u7684\u6587\u5b57\u8655\u7406\u5c08\u6848&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1247,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","pagelayer_contact_templates":[],"_pagelayer_content":"","_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[9],"tags":[],"class_list":["post-1143","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts\/1143","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1143"}],"version-history":[{"count":3,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts\/1143\/revisions"}],"predecessor-version":[{"id":1156,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts\/1143\/revisions\/1156"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/media\/1247"}],"wp:attachment":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1143"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1143"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1143"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}