{"id":1124259,"date":"2025-01-08T19:39:40","date_gmt":"2025-01-08T11:39:40","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1124259.html"},"modified":"2025-01-08T19:39:43","modified_gmt":"2025-01-08T11:39:43","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e6%89%be%e5%87%ba%e4%b8%80%e7%99%be%e4%bb%a5%e5%86%85%e7%9a%84%e6%89%80%e6%9c%89%e5%ae%8c%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1124259.html","title":{"rendered":"\u5982\u4f55\u7528Python\u627e\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25085404\/055e137a-3b97-4064-b6b4-4d61752e9543.webp\" alt=\"\u5982\u4f55\u7528Python\u627e\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u7528Python\u627e\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570<\/strong><\/p>\n<\/p>\n<p><p><strong>\u627e\u5230\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5176\u4e2d\u4e00\u79cd\u9ad8\u6548\u7684\u65b9\u6cd5\u662f\u5229\u7528Python\u7f16\u7a0b\u3002<\/strong>\u3001<strong>\u5b8c\u6570\uff08Perfect Number\uff09\u662f\u6307\u4e00\u4e2a\u6570\u6070\u597d\u7b49\u4e8e\u5b83\u7684\u6240\u6709\u771f\u56e0\u6570\uff08\u5373\u9664\u4e86\u5b83\u81ea\u8eab\u4ee5\u5916\u7684\u56e0\u6570\uff09\u4e4b\u548c<\/strong>\u3001<strong>\u5728\u7f16\u5199\u7a0b\u5e8f\u4e4b\u524d\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u7406\u89e3\u5b8c\u6570\u7684\u6982\u5ff5\uff0c\u5e76\u4e14\u638c\u63e1\u57fa\u672c\u7684Python\u7f16\u7a0b\u6280\u5de7<\/strong>\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u7528Python\u627e\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570\u3002<\/p>\n<\/p>\n<p><p>\u5b8c\u6570\u662f\u6570\u5b66\u4e2d\u7684\u4e00\u79cd\u7279\u6b8a\u6570\uff0c\u5b83\u7684\u5b9a\u4e49\u662f\uff1a\u4e00\u4e2a\u6b63\u6574\u6570\u7b49\u4e8e\u9664\u5b83\u672c\u8eab\u4ee5\u5916\u7684\u6240\u6709\u6b63\u56e0\u6570\u4e4b\u548c\u3002\u6bd4\u5982\uff0c6\u662f\u4e00\u4e2a\u5b8c\u6570\uff0c\u56e0\u4e3a6 = 1 + 2 + 3\u3002\u5b8c\u6570\u5728\u6570\u8bba\u4e2d\u6709\u7740\u91cd\u8981\u7684\u5730\u4f4d\u548c\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b8c\u6570\u7684\u57fa\u672c\u6982\u5ff5<\/h3>\n<\/p>\n<p><p>\u5b8c\u6570\uff08Perfect Number\uff09\u662f\u6307\u4e00\u4e2a\u6570\u6070\u597d\u7b49\u4e8e\u5b83\u7684\u6240\u6709\u771f\u56e0\u6570\uff08\u5373\u9664\u4e86\u5b83\u81ea\u8eab\u4ee5\u5916\u7684\u56e0\u6570\uff09\u4e4b\u548c\u3002\u5b8c\u6570\u7684\u6982\u5ff5\u6700\u65e9\u7531\u53e4\u5e0c\u814a\u6570\u5b66\u5bb6\u6b27\u51e0\u91cc\u5fb7\u63d0\u51fa\uff0c\u5e76\u4e14\u4ed6\u8bc1\u660e\u4e86\u67d0\u4e9b\u7279\u5b9a\u5f62\u5f0f\u7684\u6570\u662f\u5b8c\u6570\u3002<\/p>\n<\/p>\n<p><p>\u5b8c\u6570\u6709\u51e0\u4e2a\u91cd\u8981\u7684\u6027\u8d28\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u5b8c\u6570\u662f\u5076\u6570\u3002<\/li>\n<li>\u5b8c\u6570\u7684\u5f62\u5f0f\u53ef\u4ee5\u901a\u8fc7\u6b27\u51e0\u91cc\u5fb7-\u6b27\u62c9\u5b9a\u7406\u8868\u793a\uff0c\u5373\u5982\u679c (2^{p-1}(2^p &#8211; 1)) \u662f\u4e00\u4e2a\u5b8c\u6570\uff0c\u90a3\u4e48 (2^p &#8211; 1) \u5fc5\u987b\u662f\u4e00\u4e2a\u7d20\u6570\u3002<\/li>\n<li>\u5b8c\u6570\u7684\u524d\u51e0\u4e2a\u4f8b\u5b50\u662f\uff1a6\u300128\u3001496\u30018128\u3002<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001Python\u7f16\u7a0b\u57fa\u7840<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u719f\u6089\u4ee5\u4e0bPython\u7f16\u7a0b\u57fa\u7840\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u57fa\u672c\u8bed\u6cd5<\/strong>\uff1a\u5305\u62ec\u53d8\u91cf\u3001\u6570\u636e\u7c7b\u578b\u3001\u8fd0\u7b97\u7b26\u7b49\u3002<\/li>\n<li><strong>\u5faa\u73af\u7ed3\u6784<\/strong>\uff1a\u5982for\u5faa\u73af\u548cwhile\u5faa\u73af\u3002<\/li>\n<li><strong>\u6761\u4ef6\u5224\u65ad<\/strong>\uff1a\u5982if-else\u7ed3\u6784\u3002<\/li>\n<li><strong>\u51fd\u6570\u5b9a\u4e49<\/strong>\uff1a\u5982\u4f55\u5b9a\u4e49\u548c\u8c03\u7528\u51fd\u6570\u3002<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u627e\u51fa\u5b8c\u6570\u7684\u7b97\u6cd5\u6b65\u9aa4<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u627e\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u6765\u7f16\u5199\u7a0b\u5e8f\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u521d\u59cb\u5316\u4e00\u4e2a\u7a7a\u5217\u8868<\/strong>\uff0c\u7528\u4e8e\u5b58\u50a8\u627e\u5230\u7684\u5b8c\u6570\u3002<\/li>\n<li><strong>\u5faa\u73af\u904d\u53861\u5230100\u4e4b\u95f4\u7684\u6240\u6709\u6570<\/strong>\u3002<\/li>\n<li><strong>\u5bf9\u4e8e\u6bcf\u4e2a\u6570\uff0c\u627e\u51fa\u5b83\u7684\u6240\u6709\u771f\u56e0\u6570<\/strong>\uff0c\u5e76\u8ba1\u7b97\u8fd9\u4e9b\u56e0\u6570\u7684\u548c\u3002<\/li>\n<li><strong>\u5224\u65ad\u8fd9\u4e2a\u6570\u662f\u5426\u7b49\u4e8e\u5b83\u7684\u771f\u56e0\u6570\u4e4b\u548c<\/strong>\uff0c\u5982\u679c\u662f\uff0c\u5219\u5c06\u5176\u6dfb\u52a0\u5230\u5b8c\u6570\u5217\u8868\u4e2d\u3002<\/li>\n<li><strong>\u8f93\u51fa\u5b8c\u6570\u5217\u8868<\/strong>\u3002<\/li>\n<\/ol>\n<p><h3>\u56db\u3001Python\u4ee3\u7801\u5b9e\u73b0<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684Python\u7a0b\u5e8f\uff0c\u7528\u4e8e\u627e\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def find_perfect_numbers(limit):<\/p>\n<p>    perfect_numbers = []<\/p>\n<p>    for num in range(1, limit + 1):<\/p>\n<p>        sum_of_divisors = 0<\/p>\n<p>        for i in range(1, num):<\/p>\n<p>            if num % i == 0:<\/p>\n<p>                sum_of_divisors += i<\/p>\n<p>        if sum_of_divisors == num:<\/p>\n<p>            perfect_numbers.append(num)<\/p>\n<p>    return perfect_numbers<\/p>\n<p>if __name__ == &quot;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&quot;:<\/p>\n<p>    limit = 100<\/p>\n<p>    perfect_numbers = find_perfect_numbers(limit)<\/p>\n<p>    print(f&quot;One hundred within perfect numbers: {perfect_numbers}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4ee3\u7801\u8be6\u89e3<\/h3>\n<\/p>\n<p><h4>1\u3001\u5b9a\u4e49\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3a<code>find_perfect_numbers<\/code>\u7684\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u53c2\u6570<code>limit<\/code>\uff0c\u8868\u793a\u8981\u627e\u51fa\u5b8c\u6570\u7684\u8303\u56f4\u4e0a\u9650\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def find_perfect_numbers(limit):<\/p>\n<p>    perfect_numbers = []<\/p>\n<p>    for num in range(1, limit + 1):<\/p>\n<p>        sum_of_divisors = 0<\/p>\n<p>        for i in range(1, num):<\/p>\n<p>            if num % i == 0:<\/p>\n<p>                sum_of_divisors += i<\/p>\n<p>        if sum_of_divisors == num:<\/p>\n<p>            perfect_numbers.append(num)<\/p>\n<p>    return perfect_numbers<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5faa\u73af\u904d\u5386<\/h4>\n<\/p>\n<p><p>\u5728\u51fd\u6570\u5185\u90e8\uff0c\u6211\u4eec\u4f7f\u7528\u4e00\u4e2afor\u5faa\u73af\u904d\u5386\u4ece1\u5230<code>limit<\/code>\uff08\u5305\u62ec<code>limit<\/code>\uff09\u4e4b\u95f4\u7684\u6240\u6709\u6574\u6570\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u6570\uff0c\u4f7f\u7528\u4e00\u4e2a\u5d4c\u5957\u7684for\u5faa\u73af\u627e\u51fa\u5b83\u7684\u6240\u6709\u771f\u56e0\u6570\uff0c\u5e76\u8ba1\u7b97\u8fd9\u4e9b\u56e0\u6570\u7684\u548c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for num in range(1, limit + 1):<\/p>\n<p>    sum_of_divisors = 0<\/p>\n<p>    for i in range(1, num):<\/p>\n<p>        if num % i == 0:<\/p>\n<p>            sum_of_divisors += i<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5224\u65ad\u5b8c\u6570<\/h4>\n<\/p>\n<p><p>\u5728\u8ba1\u7b97\u51fa\u4e00\u4e2a\u6570\u7684\u771f\u56e0\u6570\u4e4b\u548c\u540e\uff0c\u6211\u4eec\u4f7f\u7528\u4e00\u4e2aif\u8bed\u53e5\u5224\u65ad\u8fd9\u4e2a\u6570\u662f\u5426\u7b49\u4e8e\u5b83\u7684\u771f\u56e0\u6570\u4e4b\u548c\u3002\u5982\u679c\u662f\uff0c\u5219\u5c06\u5176\u6dfb\u52a0\u5230<code>perfect_numbers<\/code>\u5217\u8868\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if sum_of_divisors == num:<\/p>\n<p>    perfect_numbers.append(num)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u8fd4\u56de\u7ed3\u679c<\/h4>\n<\/p>\n<p><p>\u6700\u7ec8\uff0c\u51fd\u6570\u8fd4\u56de\u627e\u5230\u7684\u6240\u6709\u5b8c\u6570\u7684\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">return perfect_numbers<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u8fd0\u884c\u7ed3\u679c\u5206\u6790<\/h3>\n<\/p>\n<p><p>\u5f53\u6211\u4eec\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u65f6\uff0c\u7a0b\u5e8f\u4f1a\u8f93\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if __name__ == &quot;__main__&quot;:<\/p>\n<p>    limit = 100<\/p>\n<p>    perfect_numbers = find_perfect_numbers(limit)<\/p>\n<p>    print(f&quot;One hundred within perfect numbers: {perfect_numbers}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<\/p>\n<p><pre><code>One hundred within perfect numbers: [6, 28]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u8868\u660e\uff0c\u5728\u4e00\u767e\u4ee5\u5185\uff0c\u53ea\u67096\u548c28\u662f\u5b8c\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u4f18\u5316\u4e0e\u6269\u5c55<\/h3>\n<\/p>\n<p><h4>1\u3001\u7b97\u6cd5\u4f18\u5316<\/h4>\n<\/p>\n<p><p>\u4e0a\u8ff0\u7b97\u6cd5\u867d\u7136\u80fd\u591f\u6b63\u786e\u627e\u51fa\u5b8c\u6570\uff0c\u4f46\u5728\u6548\u7387\u4e0a\u53ef\u4ee5\u8fdb\u4e00\u6b65\u4f18\u5316\u3002\u6211\u4eec\u53ef\u4ee5\u5229\u7528\u4e00\u4e9b\u6570\u5b66\u6027\u8d28\u6765\u51cf\u5c11\u8ba1\u7b97\u91cf\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ea\u9700\u8981\u68c0\u67e5\u5230num\u7684\u4e00\u534a\u5373\u53ef\uff0c\u56e0\u4e3a\u5927\u4e8enum\u4e00\u534a\u7684\u6570\u4e0d\u53ef\u80fd\u662fnum\u7684\u771f\u56e0\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def find_perfect_numbers(limit):<\/p>\n<p>    perfect_numbers = []<\/p>\n<p>    for num in range(1, limit + 1):<\/p>\n<p>        sum_of_divisors = 0<\/p>\n<p>        for i in range(1, (num \/\/ 2) + 1):<\/p>\n<p>            if num % i == 0:<\/p>\n<p>                sum_of_divisors += i<\/p>\n<p>        if sum_of_divisors == num:<\/p>\n<p>            perfect_numbers.append(num)<\/p>\n<p>    return perfect_numbers<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6269\u5c55\u8303\u56f4<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u5c06\u7a0b\u5e8f\u6269\u5c55\u5230\u66f4\u5927\u7684\u8303\u56f4\uff0c\u4f8b\u5982\u627e\u51fa\u4e00\u5343\u4ee5\u5185\u6216\u4e00\u4e07\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570\u3002\u53ea\u9700\u8981\u4fee\u6539<code>limit<\/code>\u7684\u503c\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if __name__ == &quot;__main__&quot;:<\/p>\n<p>    limit = 1000  # \u6216\u800510000<\/p>\n<p>    perfect_numbers = find_perfect_numbers(limit)<\/p>\n<p>    print(f&quot;Within {limit} perfect numbers: {perfect_numbers}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u8be6\u7ec6\u4e86\u89e3\u4e86\u5982\u4f55\u7528Python\u7f16\u5199\u4e00\u4e2a\u7a0b\u5e8f\u6765\u627e\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570\u3002\u6211\u4eec\u9996\u5148\u7406\u89e3\u4e86\u5b8c\u6570\u7684\u6982\u5ff5\uff0c\u7136\u540e\u5b66\u4e60\u4e86\u57fa\u672c\u7684Python\u7f16\u7a0b\u6280\u5de7\uff0c\u63a5\u7740\u8be6\u7ec6\u8bb2\u89e3\u4e86\u627e\u51fa\u5b8c\u6570\u7684\u7b97\u6cd5\u6b65\u9aa4\uff0c\u5e76\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u4ee3\u7801\u5b9e\u73b0\u3002\u6700\u7ec8\uff0c\u6211\u4eec\u8fd8\u63a2\u8ba8\u4e86\u5982\u4f55\u4f18\u5316\u548c\u6269\u5c55\u8fd9\u4e2a\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7684\u6765\u8bf4\uff0c<strong>\u627e\u51fa\u5b8c\u6570\u4e0d\u4ec5\u662f\u4e00\u4e2a\u6709\u8da3\u7684\u6570\u5b66\u95ee\u9898\uff0c\u4e5f\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u7f16\u7a0b\u7ec3\u4e60<\/strong>\u3002\u901a\u8fc7\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u6211\u4eec\u53ef\u4ee5\u52a0\u6df1\u5bf9\u6570\u5b66\u548c\u7f16\u7a0b\u7684\u7406\u89e3\uff0c\u5e76\u63d0\u9ad8\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u7684\u80fd\u529b\u3002\u5e0c\u671b\u672c\u6587\u80fd\u591f\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5b8c\u6570\u662f\u4ec0\u4e48\uff0c\u5b83\u6709\u4ec0\u4e48\u7279\u5f81\uff1f<\/strong><br \/>\u5b8c\u6570\u662f\u6307\u4e00\u4e2a\u6b63\u6574\u6570\u7b49\u4e8e\u5b83\u7684\u6240\u6709\u6b63\u56e0\u5b50\uff08\u4e0d\u5305\u62ec\u5b83\u672c\u8eab\uff09\u7684\u548c\u3002\u6700\u8457\u540d\u7684\u5b8c\u6570\u662f6\uff0c\u56e0\u4e3a1 + 2 + 3 = 6\u3002\u4e86\u89e3\u5b8c\u6570\u7684\u7279\u5f81\u6709\u52a9\u4e8e\u66f4\u597d\u5730\u7f16\u5199\u76f8\u5173\u7684Python\u4ee3\u7801\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5224\u65ad\u4e00\u4e2a\u6570\u662f\u5426\u662f\u5b8c\u6570\uff1f<\/strong><br \/>\u8981\u5224\u65ad\u4e00\u4e2a\u6570\u662f\u5426\u662f\u5b8c\u6570\uff0c\u53ef\u4ee5\u5148\u627e\u5230\u8be5\u6570\u7684\u6240\u6709\u56e0\u5b50\uff0c\u7136\u540e\u8ba1\u7b97\u8fd9\u4e9b\u56e0\u5b50\u7684\u548c\u3002\u5982\u679c\u8fd9\u4e2a\u548c\u7b49\u4e8e\u8be5\u6570\u672c\u8eab\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u4e00\u4e2a\u5b8c\u6570\u3002\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5faa\u73af\u548c\u6761\u4ef6\u8bed\u53e5\u6765\u5b9e\u73b0\u8fd9\u4e00\u8fc7\u7a0b\u3002<\/p>\n<p><strong>\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2aPython\u793a\u4f8b\u4ee3\u7801\u6765\u627e\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u5b8c\u6570\u5417\uff1f<\/strong><br \/>\u5f53\u7136\u53ef\u4ee5\uff01\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684Python\u793a\u4f8b\u4ee3\u7801\uff0c\u7528\u4e8e\u627e\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570\uff1a<\/p>\n<pre><code class=\"language-python\">def is_perfect_number(n):\n    divisors_sum = sum(i for i in range(1, n) if n % i == 0)\n    return divisors_sum == n\n\nperfect_numbers = [i for i in range(1, 101) if is_perfect_number(i)]\nprint(perfect_numbers)\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u5b8c\u6570\uff0c\u65b9\u4fbf\u7528\u6237\u4e86\u89e3\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u7528Python\u627e\u51fa\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570 \u627e\u5230\u4e00\u767e\u4ee5\u5185\u7684\u6240\u6709\u5b8c\u6570\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5176\u4e2d\u4e00\u79cd\u9ad8\u6548\u7684\u65b9\u6cd5\u662f\u5229\u7528Pyth [&hellip;]","protected":false},"author":3,"featured_media":1124263,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1124259"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1124259"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1124259\/revisions"}],"predecessor-version":[{"id":1124267,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1124259\/revisions\/1124267"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1124263"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1124259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1124259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1124259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}