{"id":1303,"date":"2023-07-07T10:20:05","date_gmt":"2023-07-07T02:20:05","guid":{"rendered":"https:\/\/rain1024.com\/?p=1303"},"modified":"2023-08-07T20:59:56","modified_gmt":"2023-08-07T12:59:56","slug":"python%e8%a7%a3%e6%9e%90%e8%80%83%e8%af%95%e9%a2%98%e5%ba%93%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"http:\/\/rain1024.com\/index.php\/2023\/07\/07\/python%e8%a7%a3%e6%9e%90%e8%80%83%e8%af%95%e9%a2%98%e5%ba%93%e6%95%b0%e6%8d%ae\/","title":{"rendered":"python\u89e3\u6790\u8003\u8bd5\u9898\u5e93\u6570\u636e"},"content":{"rendered":"<p>\u5e94\u5355\u4f4d\u8981\u6c42\u9700\u8981\u53c2\u52a0\u67d0\u4e2a\u8003\u8bd5\uff0c\u4f46\u8003\u8bd5\u9700\u8981\u4ece\u624b\u673a\u7aef\u767b\u9646\u5b66\u4e60\uff0c1000\u591a\u9053\u9898\u9700\u8981\u6328\u4e2a\u5237\u4e00\u904d\u592a\u8fc7\u4e8e\u9ebb\u70e6\uff0c\u840c\u751f\u4e86\u628a\u9898\u76ee\u548c\u7b54\u6848\u5168\u90e8\u6252\u4e0b\u6765\u7684\u60f3\u6cd5\uff0c\u518d\u7528python\u505a\u6570\u636e\u7684\u6e05\u6d17\u548c\u68b3\u7406\uff0c\u6700\u540e\u6574\u5408\u51fa\u6765\u6240\u6709\u7684\u8003\u8bd5\u9898\u5e93\u4fe1\u606f\u3002<\/p>\n<ol>\n<li>\u9996\u5148\u6253\u5f00\u6d4f\u89c8\u5668\u5206\u6790\u6570\u636e\u5305\uff0c\u627e\u5230\u6279\u91cf\u67e5\u8be2\u5230\u7684\u9898\u76ee\u6570\u636e\uff0c\u5728Response\u53ef\u4ee5\u770b\u5230\u8fd4\u56de\u7684\u6570\u636e\uff0c\u4ece\u4e2d\u627e\u4e00\u4e0b\u5173\u952e\u9898\u76ee\uff0c\u7136\u540e\u76f4\u63a5\u62f7\u8d1d\u51fa\u6765\u5c31\u884c\uff0c\u8fd9\u4e2a\u8bf7\u6c42\u5305\u542b\u6240\u6709\u6570\u636e\uff0c\u5c31\u4e0d\u7528\u518d\u6328\u4e2a\u6a21\u62df\u8bf7\u6c42\u4e86\u3002<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/07\/post-1303-64a77656aed9d.png\" alt=\"\" \/><\/p>\n<ol start=\"2\">\n<li>\u6293\u53d6\u5230\u7684\u6570\u636e\u592a\u8fc7\u4e8e\u591a\uff0c\u5305\u542b\u4e86\u5404\u79cdhtml\u7684\u4fe1\u606f\uff0c\u53ef\u4ee5\u628a\u9898\u76ee\u7684\u6570\u636e\u5355\u72ec\u62f7\u8d1d\u51fa\u6765<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/07\/post-1303-64a776573eae7.png\" alt=\"\" \/><\/p>\n<ol start=\"3\">\n<li>\u627e\u5230json\u6570\u636e\u7684\u89c4\u5f8b\uff0c\u8ba9python\u6279\u91cf\u89e3\u6790json\u4f1a\u5bb9\u6613\u5f88\u591a\uff0c\u8fd9\u91cc\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6279\u91cf\u66ff\u6362\u7684\u529f\u80fd\uff0c\u5c06&quot;p_questions.push(&quot;\u66ff\u6362\u6210{\uff0c \u518d\u5c06&quot;})&quot;\u66ff\u6362\u6210&quot;,&quot; \uff0c\u8fd9\u6837\u5c31\u6709\u4e86json\u7684\u57fa\u672ckey-value\u7ed3\u6784\uff0c\u6700\u540e\u52a0\u4e0a[]\u4ee5\u5217\u8868\u5f62\u5f0f\u5448\u73b0\uff0c\u8fd9\u6837\u5c31\u5b8c\u6210\u4e86\u6570\u636e\u7684\u57fa\u672c\u6e05\u6d17\u3002<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/07\/post-1303-64a776579de8d.png\" alt=\"\" \/><\/p>\n<ol start=\"4\">\n<li>\u4e0b\u9762\u53ef\u4ee5\u52a0\u8f7djson\u6587\u4ef6\uff0c\u4ee5json\u7684\u5f62\u5f0f\u5904\u7406\u6570\u636e\u5217\u8868\uff0c\u9010\u4e2a\u5206\u6790\u6bcf\u4e00\u9879\u7684\u6bcf\u4e00\u4e2a\u5b57\u6bb5\u3002\u8fd9\u91cc\u53ef\u4ee5\u52a0\u5165\u4e00\u4e9b\u5f02\u5e38\u6355\u83b7\u903b\u8f91\uff0c\u9632\u6b62\u67d0\u4e2a\u9519\u8bef\u963b\u65ad\u6574\u4f53\u6d41\u7a0b\u3002<\/li>\n<\/ol>\n<pre><code>import json\n\n# \u8bfb\u53d6\u6587\u4ef6\u4e2d\u7684JSON\u6570\u636e\ndef read_json_file(file_name):\n    with open(file_name, &#039;r&#039;) as f:\n        data = json.load(f)\n    return data\n\nif __name__ == &quot;__main__&quot;:\n    data = read_json_file(&#039;data\/ti.json&#039;)\n    num = 1\n    for line in data:\n        print(str(num) + &#039;. &#039; + line[&#039;description&#039;])\n        num += 1\n        answer = json.loads(line[&#039;answer&#039;])\n        if int(line[&#039;type&#039;]) == 3:\n            if str(answer[&#039;answer&#039;]) == &#039;false&#039;:\n                print(&#039;\u7b54\u6848\uff1a\u9519&#039;)\n            else:\n                print(&#039;\u7b54\u6848\uff1a\u5bf9&#039;)\n        elif int(line[&#039;type&#039;]) == 1 or int(line[&#039;type&#039;]) == 2:\n            option = json.loads(line[&#039;option&#039;])\n            o_str = &#039;&#039;\n            for o in option:\n                o_str = o_str + o + &#039;: &#039; + option[o] + &#039;\\n&#039;\n            print(&#039;\u9009\u9879\uff1a\\n&#039; + o_str)\n            print(&#039;\u7b54\u6848\uff1a&#039; + str(answer[&#039;answer&#039;]))\n\n        if answer[&#039;analysis&#039;] is not None:\n            print(&#039;\u89e3\u6790\uff1a&#039; + answer[&#039;analysis&#039;])<\/code><\/pre>\n<p>\u6700\u7ec8\u5c06\u751f\u6210\u7684\u6570\u636e\u5bfc\u5165word\u4e2d\uff0c\u5f62\u6210\u53ef\u4ee5\u770b\u7684\u6587\u6863\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/rain1024.com\/wp-content\/uploads\/2023\/07\/post-1303-64a776581701b.png\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e94\u5355\u4f4d\u8981\u6c42\u9700\u8981\u53c2\u52a0\u67d0\u4e2a\u8003\u8bd5\uff0c\u4f46\u8003\u8bd5\u9700\u8981\u4ece\u624b\u673a\u7aef\u767b\u9646\u5b66\u4e60\uff0c1000\u591a\u9053\u9898\u9700\u8981\u6328\u4e2a\u5237\u4e00\u904d\u592a\u8fc7\u4e8e\u9ebb\u70e6\uff0c\u840c\u751f\u4e86\u628a\u9898\u76ee\u548c\u2026 <span class=\"read-more\"><a href=\"http:\/\/rain1024.com\/index.php\/2023\/07\/07\/python%e8%a7%a3%e6%9e%90%e8%80%83%e8%af%95%e9%a2%98%e5%ba%93%e6%95%b0%e6%8d%ae\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-1303","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/comments?post=1303"}],"version-history":[{"count":1,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1303\/revisions"}],"predecessor-version":[{"id":1304,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1303\/revisions\/1304"}],"wp:attachment":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media?parent=1303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/categories?post=1303"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/tags?post=1303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}