{"id":204780,"date":"2025-05-29T10:02:44","date_gmt":"2025-05-29T02:02:44","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204780\/"},"modified":"2025-05-29T10:02:44","modified_gmt":"2025-05-29T02:02:44","slug":"%e5%a6%82%e4%bd%95%e7%94%a8-python-%e4%bb%8e%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e6%8f%90%e5%8f%96%e5%b9%b6%e8%ae%a1%e7%ae%97%e6%95%b0%e5%ad%97%e7%9a%84%e6%80%bb%e5%92%8c%e6%88%96%e6%95%b0%e9%87%8f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204780\/","title":{"rendered":"\u5982\u4f55\u7528 Python \u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u5e76\u8ba1\u7b97\u6570\u5b57\u7684\u603b\u548c\u6216\u6570\u91cf\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u7528 Python \u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u5e76\u8ba1\u7b97\u6570\u5b57\u7684\u603b\u548c\u6216\u6570\u91cf\uff1f<\/h1>\n<p>\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241116\/173173107567381e8372cb9.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python \u6c42\u89e3\u7528\u6237\u8f93\u5165\u6574\u6570\uff08\u4e2a\u4f4d\u6570\uff09<\/strong><\/p>\n<p>\u95ee\u9898\u63cf\u8ff0\uff1a<br \/>\u7ed9\u5b9a\u7528\u6237\u8f93\u5165\u7684\u5185\u5bb9\uff0c\u8981\u6c42\u8ba1\u7b97\u5176\u6574\u6570\u90e8\u5206\uff08\u4ec5\u9650\u4e2a\u4f4d\u6570\uff09\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u8f93\u5165 &#8220;efghjjj5885668&#8243;\uff0c\u6211\u4eec\u9700\u8981\u63d0\u53d6\u5176\u4e2d\u7684\u6570\u5b57\u90e8\u5206\u5e76\u8ba1\u7b97\u5176\u603b\u548c\u6216\u6570\u91cf\u3002<\/p>\n<p>\u95ee\u9898\u89e3\u7b54\uff1a<\/p>\n<p>\u4e3a\u4e86\u6c42\u89e3\u8be5\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 python \u7684 for \u5faa\u73af\u904d\u5386\u8f93\u5165\u5185\u5bb9\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u6839\u636e\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li>\n<p><strong>\u6c42\u6570\u5b57\u603b\u548c<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5bf9\u6bcf\u4e2a\u5b57\u7b26\u6267\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u5982\u679c\u4e3a\u6570\u5b57\u5219\u8f6c\u6362\u6210\u6574\u6570\u3002<\/li>\n<li>\u5c06\u8f6c\u6362\u540e\u7684\u6570\u5b57\u6dfb\u52a0\u5230\u4e00\u4e2a\u7d2f\u52a0\u53d8\u91cf\u4e2d\u3002<\/li>\n<li>\u5faa\u73af\u7ed3\u675f\u540e\uff0c\u7d2f\u52a0\u53d8\u91cf\u5c06\u5305\u542b\u6574\u6570\u90e8\u5206\u7684\u603b\u548c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>total = 0\nuser_input = input(\"\u8f93\u5165\u5185\u5bb9\uff1a\")\n\nfor char in user_input:\n    if char.isdigit():\n        total += int(char)\n\nprint(\"\u6570\u5b57\u90e8\u5206\u7684\u603b\u548c\uff1a\", total)<\/pre>\n<ul>\n<li>\n<p><strong>\u6c42\u6570\u5b57\u6570\u91cf<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5bf9\u6bcf\u4e2a\u5b57\u7b26\u6267\u884c\u7c7b\u578b\u8f6c\u6362\uff0c\u5982\u679c\u4e3a\u6570\u5b57\u5219\u5c06\u4e00\u4e2a\u4e34\u65f6\u53d8\u91cf\u52a0 1\u3002<\/li>\n<li>\u5faa\u73af\u7ed3\u675f\u540e\uff0c\u4e34\u65f6\u53d8\u91cf\u5c06\u5305\u542b\u6574\u6570\u90e8\u5206\u7684\u6570\u91cf\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>count = 0\nuser_input = input(\"\u8f93\u5165\u5185\u5bb9\uff1a\")\n\nfor char in user_input:\n    if char.isdigit():\n        count += 1\n\nprint(\"\u6570\u5b57\u90e8\u5206\u7684\u6570\u91cf\uff1a\", count)<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u7528 Python \u4ece\u5b57\u7b26\u4e32\u4e2d&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204780","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204780","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204780"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204780\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}