{"id":13127,"date":"2022-11-29T14:26:58","date_gmt":"2022-11-29T06:26:58","guid":{"rendered":"https:\/\/fgchen.com\/wpedu\/?p=13127"},"modified":"2026-03-30T14:32:53","modified_gmt":"2026-03-30T06:32:53","slug":"tqc-%e7%a8%8b%e5%bc%8f%e8%aa%9e%e8%a8%80python-308-%e8%bf%b4%e5%9c%88%e4%bd%8d%e6%95%b8%e5%8a%a0%e7%b8%bd","status":"publish","type":"post","link":"https:\/\/fgchen.com\/wpedu\/2022\/11\/tqc-%e7%a8%8b%e5%bc%8f%e8%aa%9e%e8%a8%80python-308-%e8%bf%b4%e5%9c%88%e4%bd%8d%e6%95%b8%e5%8a%a0%e7%b8%bd\/","title":{"rendered":"TQC+ \u7a0b\u5f0f\u8a9e\u8a00Python 308 \u8ff4\u5708\u4f4d\u6578\u52a0\u7e3d"},"content":{"rendered":"1. \u984c\u76ee\u8aaa\u660e:\r\n\u8acb\u958b\u555fPYD308.py\u6a94\u6848\uff0c\u4f9d\u4e0b\u5217\u984c\u610f\u9032\u884c\u4f5c\u7b54\uff0c\u5c07\u8f38\u5165\u503c\u4e4b\u6bcf\u4f4d\u6578\u5168\u90e8\u52a0\u7e3d\uff0c\u4f7f\u8f38\u51fa\u503c\u7b26\u5408\u984c\u610f\u8981\u6c42\u3002\u4f5c\u7b54\u5b8c\u6210\u8acb\u53e6\u5b58\u65b0\u6a94\u70baPYA308.py\u518d\u9032\u884c\u8a55\u5206\u3002\r\n\r\n2. \u8a2d\u8a08\u8aaa\u660e\uff1a\r\n\u8acb\u4f7f\u7528\u8ff4\u5708\u6558\u8ff0\u64b0\u5beb\u4e00\u7a0b\u5f0f\uff0c\u8981\u6c42\u4f7f\u7528\u8005\u8f38\u5165\u4e00\u500b\u6578\u5b57\uff0c\u6b64\u6578\u5b57\u4ee3\u8868\u5f8c\u9762\u6e2c\u8a66\u8cc7\u6599\u7684\u6578\u91cf\u3002\u6bcf\u4e00\u7b46\u6e2c\u8a66\u8cc7\u6599\u662f\u4e00\u500b\u6b63\u6574\u6578\uff08\u7531\u4f7f\u7528\u8005\u8f38\u5165\uff09\uff0c\u5c07\u6b64\u6b63\u6574\u6578\u7684\u6bcf\u4f4d\u6578\u5168\u90e8\u52a0\u7e3d\u8d77\u4f86\u3002\r\n\r\n3. \u8f38\u5165\u8f38\u51fa\uff1a\r\n\u8f38\u5165\u8aaa\u660e\r\n\u5148\u8f38\u5165\u4e00\u500b\u6b63\u6574\u6578\u4ee3\u8868\u5f8c\u9762\u6e2c\u8a66\u8cc7\u6599\u7684\u6578\u91cf\r\n\u4f9d\u6e2c\u8a66\u8cc7\u6599\u7684\u6578\u91cf\uff0c\u518d\u8f38\u5165\u6b63\u6574\u6578\u7684\u6e2c\u8a66\u8cc7\u6599\r\n\r\n\u8f38\u51fa\u8aaa\u660e\r\n\u5c07\u6e2c\u8a66\u8cc7\u6599\u7684\u6bcf\u4f4d\u6578\u5168\u90e8\u52a0\u7e3d\r\n\r\n\u8f38\u5165\u8207\u8f38\u51fa\u6703\u4ea4\u96dc\u5982\u4e0b\uff0c\u8f38\u51fa\u7684\u90e8\u4efd\u4ee5\u7c97\u9ad4\u5b57\u8868\u793a 1\r\n1\r\n98765\r\nSum of all digits of 98765 is 35\r\n\r\n\u8f38\u5165\u8207\u8f38\u51fa\u6703\u4ea4\u96dc\u5982\u4e0b\uff0c\u8f38\u51fa\u7684\u90e8\u4efd\u4ee5\u7c97\u9ad4\u5b57\u8868\u793a 2\r\n3\r\n32412\r\nSum of all digits of 32412 is 12\r\n0\r\nSum of all digits of 0 is 0\r\n769\r\nSum of all digits of 769 is 22\r\n\r\n&nbsp;\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\"># TODO\r\n\r\n\r\n\"\"\"\r\nSum of all digits of _ is _\r\n\"\"\"\r\nn = int(input())\r\nfor n in range(1, n+1):\r\n    a = int(input())\r\n    print(\"Sum of all digits of\", a , \"is \", end='')\r\n    sum = 0\r\n    while a &gt; 0:\r\n        sum = sum + (a % 10)\r\n        a = a \/\/ 10\r\n\r\n    print(sum)\r\n<\/pre>\r\n&nbsp;","protected":false},"excerpt":{"rendered":"<p>1. \u984c\u76ee\u8aaa\u660e: \u8acb\u958b\u555fPYD308.py\u6a94\u6848\uff0c\u4f9d\u4e0b\u5217\u984c\u610f\u9032\u884c\u4f5c\u7b54\uff0c\u5c07\u8f38\u5165\u503c\u4e4b\u6bcf &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[266],"tags":[],"class_list":["post-13127","post","type-post","status-publish","format-standard","hentry","category-266"],"_links":{"self":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/13127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/comments?post=13127"}],"version-history":[{"count":2,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/13127\/revisions"}],"predecessor-version":[{"id":13509,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/posts\/13127\/revisions\/13509"}],"wp:attachment":[{"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/media?parent=13127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/categories?post=13127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgchen.com\/wpedu\/wp-json\/wp\/v2\/tags?post=13127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}