{"id":1289,"date":"2022-03-29T22:46:33","date_gmt":"2022-03-29T14:46:33","guid":{"rendered":"https:\/\/104.es\/?p=1289"},"modified":"2022-03-29T22:46:33","modified_gmt":"2022-03-29T14:46:33","slug":"cyberpi-tester","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2022\/03\/29\/cyberpi-tester\/","title":{"rendered":"CyberPi \u8003\u8a66\u6a5f\u88fd\u4f5c"},"content":{"rendered":"\n<p>\u5c0f\u5de7\u7684CyberPi\u7528\u4f86\u4f5c\u70ba\u7b54\u984c\u6a5f\u5176\u5be6\u6eff\u597d\u73a9\u7684\uff0c\u9019\u7bc7\u6587\u7ae0\u5c31\u4f86\u6559\u540c\u5b78\u5011\u5982\u4f55\u5229\u7528Python\u7684\u5143\u7d44\u4e32\u5217\u4ee5\u53ca\u8ff4\u5708\uff0c\u5728CyberPi\u4e0a\u88fd\u4f5c\u4e00\u500b\u6709\u8da3\u7684\u8003\u8a66\u6a5f\u3002\u7a0b\u5f0f\u4e00\u958b\u59cb\u57f7\u884c\u7684\u6642\u5019\uff0cCyberPi\u5c31\u6703\u9023\u7e8c\u51fa10\u500b\u554f\u984c\u8b93\u4f60\u56de\u7b54\uff0c\u5728\u7b54\u984c\u5b8c\u7562\u4e4b\u5f8c\u518d\u986f\u793a\u4f60\u6240\u7372\u5f97\u7684\u5206\u6578\u3002<\/p>\n\n\n\n<p>\u5148\u4f86\u770b\u4e00\u4e0b\u57f7\u884c\u7684\u7d50\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Cyber Pi \u6e2c\u9a57\u6a5f\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/OnHjADZr1xI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\u65e2\u7136\u8981\u51fa\u984c\u7d66\u4f7f\u7528\u8005\u56de\u7b54\uff0c\u6700\u91cd\u8981\u7684\u4e8b\u7576\u7136\u662f\u984c\u76ee\u56c9\u3002\u9664\u4e86\u984c\u76ee\u4e4b\u5916\uff0c\u6211\u5011\u9084\u9700\u8981\u7d66\u500b\u7b54\u6848\uff0c\u56e0\u6b64\u984c\u76ee\u8cc7\u6599\u662f\u4ee5\u5982\u4e0b\u7684\u5f62\u5f0f\u4f86\u5448\u73fe\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>items = &#091;\n    ('1.\u8acb\u554f\u9ad8\u79d1\u5927\u6709\u5e7e\u500b\u6821\u5340\uff1f\\nA.5\u500b B.3\u500b', 'A'),\n    ('2.\u8acb\u554f\u6893\u5b98\u5340\u4f4d\u65bc\u54ea\u4e00\u500b\u7e23\u5e02\uff1f\\nA.\u9ad8\u96c4\u5e02 B.\u5c4f\u6771\u7e23', 'A'),\n    ('3.\u8acb\u554f\u9ad8\u79d1\u5927\u4e0d\u5206\u7cfb\u4f4d\u65bc\u54ea\u4e00\u500b\u6821\u5340\uff1f\\nA.\u7b2c\u4e00 B.\u6960\u6893', 'B'),\n    ('4.\u4ee5\u4e0b\u54ea\u4e00\u7a2e\u9b5a\u7684\u9ad4\u578b\u8f03\u5927\uff1f\\nA.\u9f8d\u81bd\u77f3\u6591 B.\u91d1\u76ee\u9c78\u9b5a', 'A'),\n    ('5.\u8acb\u554f\u86b5\u4ed4\u5bee\u6f01\u6e2f\u4f4d\u65bc\u54ea\u4e00\u500b\u884c\u653f\u5340\uff1f\\nA.\u6c38\u5b89\u5340 B.\u6893\u5b98\u5340', 'B'),\n    ('6.\u6893\u5b98\u5340\u7684\u8fb2\u696d\u4e3b\u8981\u5317\u90e8\u9084\u662f\u5357\u90e8\uff1f\\nA.\u5357 B.\u5317', 'B'),\n    ('7.\u86b5\u4ed4\u5bee\u6f01\u6e2f\u6f01\u5e02\u53ea\u62cd\u8ce3\u81ea\u5df1\u7684\u6f01\u8ca8\uff1f\\nA.\u662f B.\u4e0d\u662f', 'B'),\n    ('8.\u73fe\u968e\u6bb5\u53f0\u7063\u73fe\u6488\u6f01\u7372\u4e4b\u51a0\u662f\u54ea\u4e00\u500b\u6f01\u6e2f\uff1f\\nA.\u86b5\u4ed4\u5bee B.\u6c38\u5b89', 'A'),\n    ('9.\u8ddd\u96e2\u86b5\u4ed4\u5bee\u6f01\u6e2f\u6700\u8fd1\u7684\u9ad8\u79d1\u5927\u6821\u5340\u662f\uff1f\\nA.\u65d7\u6d25 B.\u6960\u6893', 'B'),\n    ('10.\u51fa\u6d77\u53e3\u96e2\u86b5\u4ed4\u5bee\u6f01\u6e2f\u6700\u8fd1\u7684\u662f\u54ea\u4e00\u689d\u6eaa\uff1f\\nA.\u5178\u5bf6\u6eaa B.\u5f8c\u52c1\u6eaa', 'A'),\n    ]<\/code><\/pre>\n\n\n\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\u6211\u5011\u7e3d\u5171\u51fa\u4e8610\u984c\uff0c\u914d\u5408CyberPi\u7684\u6309\u9215\uff0c\u5728\u6b64\u8a2d\u8a08\u7684\u984c\u76ee\u9078\u9805\u53ea\u67092\u500b\uff0c\u5206\u5225\u662fA\u548cB\uff0c\u5982\u679c\u4f7f\u7528\u8005\u6309\u4e0b\u6309\u9215A\u5c31\u7b49\u65bc\u662f\u56de\u7b54\u4e86A\uff0c\u540c\u7406\u6309\u9215B\u4e5f\u7b49\u65bc\u662f\u56de\u7b54B\u3002\u90a3\u9ebc\uff0c\u8a72\u5982\u4f55\u53d6\u5f97\u4f7f\u7528\u8005\u7684\u56de\u7b54\u5462\uff1f\u6211\u5011\u4f7f\u7528\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\uff0c\u70ba\u4e86\u65b9\u4fbf\u4f7f\u7528\u8d77\u898b\uff0c\u9019\u6bb5\u7a0b\u5f0f\u78bc\u8a2d\u8a08\u6210\u81ea\u8a02\u51fd\u5f0fget_answer()\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def get_answer(answer):\n    ret = False\n    cp.controller.reset_count(\"a\")\n    cp.controller.reset_count(\"b\")\n    while cp.controller.get_count(\"a\") == 0 and cp.controller.get_count(\"b\") == 0:\n        pass\n    if answer==\"A\" and cp.controller.get_count(\"a\")&gt;0:\n        ret = True\n    elif answer==\"B\" and cp.controller.get_count(\"b\")&gt;0:\n        ret = True\n    return ret<\/code><\/pre>\n\n\n\n<p>\u81ea\u8a02\u51fd\u5f0fget_answer(answer)\u6703\u5148\u50b3\u5165\u6b63\u78ba\u7684\u7b54\u6848\u662f&#8217;A&#8217;\u9084\u662f&#8217;B&#8217;\uff0c\u4e00\u958b\u59cb\u5047\u8a2d\u56de\u7b54\u7684\u7d50\u679c\u662f\u932f\u7684\uff08ret=False\uff09\uff0c\u7136\u5f8c\u70ba\u4e86\u907f\u514d\u4e0a\u6b21\u7684\u6309\u9215\u72c0\u614b\u5f71\u97ff\u5230\u672c\u6b21\u7684\u5224\u65b7\uff0c\u5148\u628a\u6309\u9215\uff21\u548c\u6309\u9215\uff22\u7684\u6309\u9375\u6b21\u6578\u91cd\u7f6e\u3002\u63a5\u8457\uff0c\u5229\u7528\u4e00\u500bwhile\u8ff4\u5708\u7b49\u5f85\uff21\u6216\uff22\u5176\u4e2d\u4e00\u500b\u6309\u9215\u88ab\u6309\u4e0b\uff0c\u5728\u6309\u4e0b\u4e4b\u5f8c\uff0c\u5c31\u6839\u64da\u6a19\u6e96\u7b54\u6848answer\u7684\u5167\u5bb9\u4f86\u6838\u5c0d\u662f\u5426\u662f\u4e00\u81f4\u7684\u6309\u9215\uff0c\u5982\u679c\u662f\u7684\u8a71\uff0c\u5c31\u628aret\u6539\u70baTrue\u3002\u6700\u7d42\uff0c\u518d\u628a\u7b54\u6848\u56de\u50b3\u3002<\/p>\n\n\n\n<p>\u6709\u4e86\u4ee5\u4e0a\u7684\u8cc7\u6599\u548c\u5de5\u5177\u4e4b\u5f8c\uff0c\u4e3b\u7a0b\u5f0f\u5c31\u5bb9\u6613\u591a\u4e86\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>score = 0\nfor item in items:\n    cp.display.clear()\n    cp.console.println(item&#091;0])\n    if get_answer(item&#091;1]):\n        cp.audio.play(\"wow\")\n        score = score + 10\n    else:\n        cp.audio.play(\"sad\")\ncp.display.clear()\ncp.display.show_label(\"{}\u5206\".format(score), 24, \"center\", \"center\")<\/code><\/pre>\n\n\n\n<p>\u4e00\u958b\u59cb\u5148\u628ascore\u8b8a\u6578\u8a2d\u70ba0\uff0c\u7136\u5f8c\u5229\u7528for\u8ff4\u5708\u628a\u6bcf\u4e00\u500b\u984c\u76ee\u90fd\u53d6\u51fa\u4f86\uff0c\u5148\u6e05\u9664\u986f\u793a\u5e55\uff0c\u7136\u5f8c\u986f\u793a\u51fa\u984c\u76ee\uff0c\u518d\u628a\u6a19\u6e96\u7b54\u6848\u9001\u53bbget_answer()\u51fd\u5f0f\u4ee5\u7b49\u5f85\u4f7f\u7528\u8005\u7684\u6309\u9375\u72c0\u614b\uff0c\u4f9d\u7167\u7b54\u5c0d\u6216\u7b54\u932f\u8a08\u7b97\u5206\u6578\u4ee5\u53ca\u986f\u793a\u56de\u61c9\u7684\u97f3\u6548\u3002<\/p>\n\n\n\n<p>\u5728\u8ff4\u5708\u57f7\u884c\u5b8c\u7562\uff0c\u4e5f\u5c31\u662f\u6240\u6709\u7684\u984c\u76ee\u554f\u5b8c\u4e4b\u5f8c\uff0c\u518d\u628a\u6700\u7d42\u7684\u5206\u6578\u986f\u793a\u5728\u756b\u9762\u7684\u6b63\u4e2d\u9593\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u5de7\u7684CyberPi\u7528\u4f86\u4f5c\u70ba\u7b54\u984c\u6a5f\u5176\u5be6\u6eff\u597d\u73a9\u7684\uff0c\u9019\u7bc7\u6587\u7ae0\u5c31\u4f86\u6559\u540c\u5b78\u5011\u5982\u4f55\u5229\u7528Python\u7684\u5143\u7d44\u4e32\u5217\u4ee5\u53ca\u8ff4\u5708\uff0c\u5728CyberPi\u4e0a\u88fd\u4f5c\u4e00\u500b\u6709\u8da3\u7684\u7b54\u984c\u6a5f\u3002\u7a0b\u5f0f\u4e00\u958b\u59cb\u57f7\u884c\u7684\u6642\u5019\uff0cCyberPi\u5c31\u6703\u9023\u7e8c\u51fa10\u500b\u554f\u984c\u8b93\u4f60\u56de\u7b54\uff0c\u5728\u7b54\u984c\u5b8c\u7562\u4e4b\u5f8c\u518d\u986f\u793a\u4f60\u6240\u7372\u5f97\u7684\u5206\u6578\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1289","post","type-post","status-publish","format-standard","hentry","category-cyber-pi"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/comments?post=1289"}],"version-history":[{"count":0,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1289\/revisions"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=1289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=1289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=1289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}