{"id":1109,"date":"2022-01-29T18:25:03","date_gmt":"2022-01-29T10:25:03","guid":{"rendered":"https:\/\/www.lanxy.ink\/?p=1109"},"modified":"2022-01-29T20:34:42","modified_gmt":"2022-01-29T12:34:42","slug":"python-%e7%bb%83%e4%b9%a09-15-%e5%bd%a9%e7%a5%a8%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.lanxy.ink\/?p=1109","title":{"rendered":"Python \u7ec3\u4e609-15 \u5f69\u7968\u5206\u6790"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u9898\u76ee\u4e3a\uff1a<\/p><cite>\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u5faa\u73af\u6765\u660e\u767d\u524d\u8ff0\u5f69\u7968\u5927\u5956\u6709\u591a\u96be\u4e2d\u5956\u3002\u4e3a\u6b64\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a my_ticket \u7684\u5217\u8868\u6216\u5143\u7ec4\uff0c\u518d\u7f16\u5199\u4e00\u4e2a\u5faa\u73af\uff0c\u4e0d\u65ad\u5730\u968f\u673a\u9009\u62e9\u6570\u6216\u8005\u5b57\u6bcd\uff0c\u76f4\u5230\u4e2d\u5927\u5956\u4e3a\u6b62\u3002\u8bf7\u6253\u5370\u4e00\u6761\u6d88\u606f\uff0c\u62a5\u544a\u6267\u884c\u5faa\u73af\u591a\u5c11\u6b21\u624d\u4e2d\u4e86\u5927\u5956\u3002<\/cite><\/blockquote>\n\n\n\n<p>\u4e2a\u4eba\u7684\u601d\u8def\u4e3a\uff1a\u4e24\u4e2a\u5217\u8868A\u548cB\uff0cA\u88c5\u7740\u6240\u6709\u53ef\u4ee5\u4e2d\u5956\u7684\u5b57\u7b26\uff0cB\u88c5\u7740\u81ea\u5df1\u9009\u7684\u82e5\u5e72\u5b57\u7b26\uff0c\u7136\u540e\u4eceA\u4e2d\u9009\u51fa\u540cB\u5185\u5143\u7d20\u4e2a\u6570\u4e00\u81f4\u7684\u5b57\u7b26\u51fa\u6765\uff08\u6bd4\u5982\u81ea\u5df1\u5148\u90096\u4e2a\u5b57\u7b26\u653e\u8fdbB\u91cc\uff0c\u7136\u540e\u4e5f\u5728A\u91cc\u968f\u673a\u90096\u4e2a\u5b57\u7b26\u51fa\u6765\uff09\uff0c\u88c5\u8fdbC\u91cc\uff0c\u5c06B\u4e0eC\u6392\u5e8f\u540e\u8fdb\u884c\u6bd4\u8f83\uff0c\u4e0d\u76f8\u540c\u5219\u8ba1\u6570\u53d8\u91cf+1\uff0c\u7ee7\u7eed\u5faa\u73af\uff1b\u82e5\u76f8\u540c\u5219\u4e2d\u5956\uff0c\u6700\u540e\u8f93\u51fa\u5faa\u73af\u7684\u6b21\u6570\u3002<\/p>\n\n\n\n<p>\u81ea\u5df1\u7684&#8221;\u5956\u5238&#8221;\u91cc\u53ef\u4ee5\u542b\u6709\u76f8\u540c\u7684\u5b57\u7b26\uff0c\u4e5f\u4e0d\u8003\u8651\u5b57\u7b26\u7684\u987a\u5e8f\u6392\u5217\u3002<\/p>\n\n\n\n<p>\u5148\u5bfc\u5165\u4e24\u4e2a\u6a21\u5757\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from random import choice\nimport operator<\/code><\/pre>\n\n\n\n<p>choice\u8d1f\u8d23\u968f\u673a\u9009\u62e9\u5217\u8868\u4e2d\u7684\u5143\u7d20\uff0coperator\u4e2d\u7684\u65b9\u6cd5eq\u8d1f\u8d23\u6bd4\u8f83\u4e24\u4e2a\u5217\u8868\u662f\u5426\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u521b\u5efa\u4e2d\u5956\u5b57\u7b26\u5217\u8868\u548c\u81ea\u9009\u5b57\u7b26\u5217\u8868\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>elements = &#91;'1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f']\n# \u5f69\u7968\u4e2d\u6240\u6709\u4e2d\u5956\u5b57\u7b26\nmy_ticket = &#91;'7','3','9','1','9','b']\n# \u6211\u9009\u62e9\u7684\u5b57\u7b26<\/code><\/pre>\n\n\n\n<p>\u8fdb\u800c\u5f00\u59cb\u521b\u5efa\u5faa\u73af\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>length = len(my_ticket)\n# \u9009\u597d\u7684\u4e2d\u5956\u5b57\u7b26\u4e2a\u6570\nrange_len = length + 1\nactive = True\ntimes = 1\n# \u8ba1\u6570\u53d8\u91cf\nbingo_string = ''\nwhile active:\n\tbingo = &#91;]\n\tfor i in range(1,range_len):\n\t\tbingo.append(choice(elements))\n# \u5c06\u968f\u673a\u9009\u51fa\u7684\u4e2d\u5956\u5b57\u7b26\u5b58\u5165\u4e00\u4e2a\u65b0\u7684\u5217\u8868\u91cc\n\tifequal = operator.eq(sorted(bingo),sorted(my_ticket))\n# \u6392\u5e8f\u540e\uff0c\u6bd4\u8f83\u4e24\u4e2a\u5217\u8868\u662f\u5426\u76f8\u540c\n\tif ifequal:\n# \u76f8\u540c\u4e4b\u540e ifequal \u4e3a True\n\t\tactive = False\n\t\tprint(f\"\u7b2c{times}\u6b21\uff0c\u4e2d\u5956\u4e86.\")\n\t\tfor i in bingo:\n\t\t\tbingo_string += f\"{i} \"\n\t\tprint(f\"\u4e2d\u5956\u5b57\u7b26\u4e3a: {bingo_string.rstrip()}\")\n\n\telse:\n\t\tprint(f\"\u7b2c{times}\u6b21\uff0c\u6ca1\u4e2d\u5956.\")\n\n# \u8fd9\u91cc\u9009\u62e9\u8f93\u51fa\u6bcf\u4e00\u6b21\u6ca1\u4e2d\u5956\u65f6\u5df2\u7ecf\u5faa\u73af\u7684\u6b21\u6570\uff0c\u4e5f\u53ef\u4ee5\u4e0d\u8fd9\u6837\u505a\u3002\n\t\ttimes += 1<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\u5c31\u4f1a\u5f97\u5230\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>--snip--<\/em>\n\u7b2c37980\u6b21\uff0c\u6ca1\u4e2d\u5956.\n\u7b2c37981\u6b21\uff0c\u6ca1\u4e2d\u5956.\n\u7b2c37982\u6b21\uff0c\u6ca1\u4e2d\u5956.\n\u7b2c37983\u6b21\uff0c\u4e2d\u5956\u4e86.\n\u4e2d\u5956\u5b57\u7b26\u4e3a: 1 9 7 9 b 3\n&#91;Finished in 724ms]<\/code><\/pre>\n\n\n\n<p>\u6bcf\u6b21\u7684\u7ed3\u679c\u90fd\u4e0d\u4e00\u6837\u3002<\/p>\n\n\n\n<p>\u8fd9\u6837\u53ef\u4ee5\u5f97\u5230\u5355\u6b21\u535a\u5f69\u7684\u7ed3\u679c\u3002<\/p>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7 input \u624b\u52a8\u8f93\u5165\u81ea\u5df1\u60f3\u4e70\u7684\u5f69\u5238\u4e0a\u7684\u5b57\u7b26\uff0c\u518d\u5957\u4e00\u5c42 while \u5e76\u5728\u4e2d\u5956\u4e4b\u540e\u6267\u884c\u7684\u4ee3\u7801\u4e0b\u589e\u52a0\u8be2\u95ee\u662f\u5426\u7ee7\u7eed\u535a\u5f69\u3002<\/p>\n\n\n\n<p>\u5982\u679c my_tickets \u4e2d\u542b\u6709\u76f8\u540c\u7684\u5b57\u7b26\uff0c\u5219\u5faa\u73af\u7684\u6b21\u6570\u4f1a\u591a\u5f88\u591a&#8230;<\/p>\n\n\n\n<p>\u6bd4\u5982\u53ea\u9009\u4e86\u56db\u4e2a1\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.lanxy.ink\/wp-content\/uploads\/2022\/01\/QQ\u622a\u56fe20220129181853.png'><img class=\"lazyload lazyload-style-5\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"247\" height=\"126\" data-original=\"https:\/\/www.lanxy.ink\/wp-content\/uploads\/2022\/01\/QQ\u622a\u56fe20220129181853.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-1110\"\/><\/div><\/figure><\/div>\n\n\n\n<p>\u5faa\u73af\u6b21\u6570\u90fd\u662f\u76f8\u5f53\u591a\u7684&#8230;<\/p>\n\n\n\n<p>\u7531\u4e8e choice() \u4f1a\u6709\u51e0\u7387\u9009\u62e9\u540c\u4e00\u4e2a\u5143\u7d20\uff0c\u5982\u679c\u60f3\u8981\u4e0d\u91cd\u590d\u7684\u53d6\u51fa\u5143\u7d20\u9700\u8981\u4f7f\u7528 numpy.random.choice() \u3002<\/p>\n\n\n\n<p><s>\u591a\u591a\u5c11\u5c11\u8fd8\u662f\u589e\u52a0\u4e86\u4e00\u4e9b\u6b63\u7ecf\u7684\u77e5\u8bc6&#8230;<\/s><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ec3\u4e60\u65e5\u5fd7<\/p>\n","protected":false},"author":311,"featured_media":1115,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1109","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-common"],"_links":{"self":[{"href":"https:\/\/www.lanxy.ink\/index.php?rest_route=\/wp\/v2\/posts\/1109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lanxy.ink\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lanxy.ink\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lanxy.ink\/index.php?rest_route=\/wp\/v2\/users\/311"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lanxy.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1109"}],"version-history":[{"count":6,"href":"https:\/\/www.lanxy.ink\/index.php?rest_route=\/wp\/v2\/posts\/1109\/revisions"}],"predecessor-version":[{"id":1118,"href":"https:\/\/www.lanxy.ink\/index.php?rest_route=\/wp\/v2\/posts\/1109\/revisions\/1118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lanxy.ink\/index.php?rest_route=\/wp\/v2\/media\/1115"}],"wp:attachment":[{"href":"https:\/\/www.lanxy.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lanxy.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lanxy.ink\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}