{"id":184387,"date":"2022-04-22T08:43:35","date_gmt":"2022-04-22T00:43:35","guid":{"rendered":"http:\/\/www.idc.net\/help\/184387\/"},"modified":"2022-04-22T08:43:35","modified_gmt":"2022-04-22T00:43:35","slug":"python-%e7%a8%8b%e5%ba%8f%ef%bc%9a%e4%bd%bf%e7%94%a8%e6%8e%92%e5%ba%8f%e5%af%bb%e6%89%be%e4%b8%80%e4%b8%aa%e6%95%b0%e7%9a%84%e6%9c%80%e5%b0%8f%e9%99%a4%e6%95%b0","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/184387\/","title":{"rendered":"Python \u7a0b\u5e8f\uff1a\u4f7f\u7528\u6392\u5e8f\u5bfb\u627e\u4e00\u4e2a\u6570\u7684\u6700\u5c0f\u9664\u6570"},"content":{"rendered":"<p>\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1a<\/p>\n<p>\u5728\u8fd9\u4e2a\u7b80\u5355\u7684 python \u7a0b\u5e8f\u4e2d\uff0c\u6211\u4eec\u5fc5\u987b\u4ece\u4e00\u4e2a\u5217\u8868\u4e2d\u6392\u5e8f\u5e76\u627e\u5230\u6700\u5c0f\u7684\u9664\u6570\u3002\u8fd9\u662f\u4e00\u4e2a\u57fa\u4e8e\u6570\u7ec4\u7684 python \u7a0b\u5e8f\u3002<\/p>\n<p>\u8981\u7406\u89e3\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u60a8\u5e94\u8be5\u4e86\u89e3\u4ee5\u4e0b Python \u7f16\u7a0b\u4e3b\u9898:<\/p>\n<ul>\n<li>Python \u5217\u8868<\/li>\n<li>Python \u5faa\u73af<\/li>\n<li>Python \u51b3\u7b56\u8bed\u53e5<\/li>\n<\/ul>\n<h2>python \u4e2d\u5982\u4f55\u4ece\u5217\u8868\u4e2d\u6392\u5e8f\u627e\u5230\u6700\u5c0f\u9664\u6570\uff1f<\/h2>\n<p>\u5728\u8fd9\u4e2a\u521d\u7ea7 python \u7a0b\u5e8f\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u627e\u5230\u4e00\u4e2a\u6570\u7684\u6700\u5c0f\u9664\u6570\u3002\u9664\u6570\u662f\u80fd\u88ab\u7ed9\u5b9a\u6570\u6574\u9664\u7684\u6570\u3002\u6bd4\u5982\u6211\u4eec\u53d6\u4e00\u4e2a\u6570\uff0c12 \u7684\u9664\u6570\u662f 2\uff0c3\uff0c4\uff0c6\uff0c12\uff1b\u4ece\u9664\u6570\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6253\u5370\u6700\u5c0f\u7684\u9664\u6570\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u662f 2\u3002<\/p>\n<p>\u4e3a\u4e86\u5728 python \u7f16\u7a0b\u793a\u4f8b\u4e2d\u5e94\u7528\u8fd9\u4e00\u903b\u8f91\uff0c\u6211\u4eec\u5728 python \u4e2d\u6253\u5f00\u4e00\u4e2a\u4ece 2 \u5230\u8be5\u6570\u5b57\u7684 for \u5faa\u73af\uff0c\u5e76\u5728<code>for loop<\/code>\u8fed\u4ee3\u4e2d\u4f7f\u7528 Mod \u8fd0\u7b97\u7b26\u68c0\u67e5\u6bcf\u4e2a\u6570\u5b57\u3002\u5728<code>for loop<\/code>\u7684\u6bcf\u6b21\u8fed\u4ee3\u4e4b\u540e\uff0c\u6211\u4eec\u5fc5\u987b\u4f7f\u7528 python \u4e2d\u7684 if \u6761\u4ef6\u8bed\u53e5\u68c0\u67e5 mod i \u662f\u5426\u4e3a\u96f6\uff0c\u5e76\u4f7f\u7528<code>append()<\/code>\u65b9\u6cd5\u5c06\u9664\u6570\u6dfb\u52a0\u5230\u5217\u8868\u4e2d\u3002\u5728\u6211\u4eec\u5c06\u6709\u4e00\u4e2a python \u9664\u6570\u5217\u8868\u4e4b\u540e\uff0c\u73b0\u5728\u5e94\u7528\u5217\u8868\u4e0a\u7684<code>sort()<\/code>\u51fd\u6570\u4ee5\u5347\u5e8f\u5bf9\u5217\u8868\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p>\u6ce8\u610f:<code>Sort()<\/code>python \u4e2d\u7684\u51fd\u6570\u9ed8\u8ba4\u4f1a\u6309\u7167\u5347\u5e8f\u5bf9\u5217\u8868\u8fdb\u884c\u6392\u5e8f\u3002\u4e3a\u4e86\u8fdb\u884c\u964d\u5e8f\u6392\u5e8f\uff0c\u6211\u4eec\u5728\u6392\u5e8f\u51fd\u6570\u4e2d\u4f7f\u7528\u5b83\u4eec<code>reverse<\/code>\u3002<\/p>\n<h3>\u7b97\u6cd5<\/h3>\n<p>STEP 1: \u4f7f\u7528\u8f93\u5165\u51fd\u6570\u63a5\u53d7\u7528\u6237\u7684\u8f93\u5165\uff0c\u5e76\u4f7f\u7528 python \u8bed\u8a00\u4e2d\u7684<code>int()<\/code>\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\u3002<\/p>\n<p>STEP 2: \u4f7f\u7528 python \u57fa\u672c\u8bed\u6cd5\u521d\u59cb\u5316\u5217\u8868\u3002<\/p>\n<p>\u7b2c\u4e09\u6b65:\u7528\u4e00\u4e2a\u4ece 2 \u5230\u6570\u5b57\u7684<code>for loop<\/code>\u6765\u68c0\u67e5\u6bcf\u4e2a\u6570\u5b57\u662f\u4e0d\u662f\u9664\u6570\u3002<\/p>\n<p>\u6b65\u9aa4 4: \u4f7f\u7528<code>if<\/code>\u6761\u4ef6\u548c mod \u8fd0\u7b97\u7b26\u68c0\u67e5\u5b83\u662f\u5426\u662f\u5b8c\u7f8e\u9664\u6570\uff0c\u5982\u679c\u662f\u9664\u6570\uff0c\u5219\u4f7f\u7528 python \u4e2d\u7684<code>append()<\/code>\u65b9\u6cd5\u8ffd\u52a0\u5230\u5217\u8868\u4e2d\u3002<\/p>\n<p>STEP 5: \u5e94\u7528\u5217\u8868\u6392\u5e8f\u529f\u80fd\uff0c\u5f97\u5230\u6309\u5347\u5e8f\u6392\u5e8f\u7684 python \u5217\u8868\u3002<\/p>\n<p>STEP 6: \u6253\u5370\u4f4d\u7f6e\u5217\u8868\u30100\u3011\u4e2d\u7684\u5143\u7d20\uff0c\u56e0\u4e3a\u5b83\u662f\u6570\u5b57\u7684\u6700\u4f4e\u9664\u6570\u3002<\/p>\n<h2>Python \u6e90\u4ee3\u7801<\/h2>\n<pre><code>n=int(input(\"Enter an number:\"))\n\na=[]\n\nfor i in range(2,n+1):\n\n    if(n%i==0):\n\n        a.append(i)    # add the divisors to a list\n\na.sort()    # sort the list\n\nprint(\"Smallest divisor is:\",a[0])   # print the first element in the list\n<\/code><\/pre>\n<h2>\u8f93\u51fa<\/h2>\n<pre><code>Enter an number: 15\n\nSmallest divisor is: 3<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1a \u5728\u8fd9\u4e2a\u7b80\u5355\u7684 python \u7a0b\u5e8f\u4e2d\uff0c\u6211\u4eec\u5fc5\u987b\u4ece\u4e00\u4e2a\u5217\u8868\u4e2d\u6392\u5e8f\u5e76\u627e\u5230\u6700\u5c0f\u7684\u9664\u6570\u3002\u8fd9\u662f\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-184387","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/184387","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=184387"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/184387\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=184387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=184387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=184387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}