{"id":83,"date":"2021-11-23T20:51:06","date_gmt":"2021-11-23T12:51:06","guid":{"rendered":"http:\/\/homeyk.com\/?p=83"},"modified":"2024-07-07T19:18:55","modified_gmt":"2024-07-07T11:18:55","slug":"%e5%bc%95%e5%85%a5%e9%9a%8f%e6%9c%ba%e6%95%b0%e7%9a%84%e6%b8%b8%e6%88%8f","status":"publish","type":"post","link":"http:\/\/homeyk.com\/?p=83","title":{"rendered":"python | \u5f15\u5165\u968f\u673a\u6570\u7684\u6e38\u620f"},"content":{"rendered":"\n<p>1\u3001random\u6a21\u5757\u53ef\u4ee5\u5f15\u5165\u968f\u673a\u6570<\/p>\n\n\n\n<p>2\u3001\u968f\u673a\u6570\u7684\u4ea7\u751f\u662f\u76f8\u540c\u6982\u7387\u7684\u3002\u4f46\u662f\u5047\u5982\u5206\u522b\u5c06\u4e0d\u540c\u6570\u91cf\u7684\u968f\u673a\u6570\u5212\u5206\u5230\u4e3a\u4e00\u4e2a\u533a\u57df\uff0c\u4ea7\u751f\u67d0\u6570\u5728\u8be5\u533a\u57df\u7684\u6982\u7387\u5c06\u662f\u6570\u91cf\u4e4b\u548c\u3002\u533a\u57df\u8d8a\u5927\uff0c\u6982\u7387\u8d8a\u5927\u3002\u6b64\u4e3a\u6b65\u957f<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"http:\/\/homeyk.com\/wp-content\/uploads\/2021\/11\/684558-20161010114747039-855546126-504x464.png\" alt=\"\" class=\"wp-image-84\"\/><\/figure>\n\n\n\n<p>3\u3001\u5229\u7528\u4e0d\u540c\u6b65\u957f\u4ee3\u8868\u4e0d\u540c\u6982\u7387\u7684\u7406\u5ff5\uff0c\u8bbe\u8ba1\u4e00\u4e2a\u6295\u5e01\u7684\u6e38\u620f\u3002\u7b97\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import random\n\nprint(\"\u6765\u73a9\u731c\u786c\u5e01\u7684\u6e38\u620f\u5427\uff01\u5b83\u662f\u5b57\u3001\u82b1\u8fd8\u662f\u7acb\u4f4f\u5462\uff1f\")\na = 0\ncount = 0\nwhile a != 100:\n    count += 1\n    a = random.randint(0, 100)\n    aStep = int(a\/50)\n    coin = (\"\u82b1\", \"\u5b57\", \"\u7acb\")\n    print(f\"\u7b2c {count} \u6b21: {coin&#91;aStep]}\")\n\nprint(f\"****\u606d\u559c\u4f60****\\n\u5728\u7b2c {count} \u6b21\u6295\u5e01\u65f6\uff0c\u786c\u5e01\u7acb\u4f4f\u4e86\")<\/code><\/pre>\n\n\n\n<p>4\u3001\u6295\u5e01\u6e38\u620f\u7684\u65b0\u73a9\u6cd5\uff0c\u5728\u8bbe\u5b9a\u6982\u7387\u7684\u60c5\u51b5\u4e0b\uff0c\u89c2\u5bdf\u5b9e\u9645\u4f1a\u51fa\u73b0\u7684\u7ed3\u679c\u3002\u4ee5\u4e0b\u4ee3\u7801\u540c\u65f6\u4e5f\u66f4\u65b0\u4e86\u5229\u7528\u6b65\u957f\u7684\u6982\u7387<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import random #\u5bfc\u5165\u968f\u673a\u6a21\u5757\n\nb=int(input(\"1000\u6b21\u6295\u5e01\u4e2d\uff0c\u4f60\u89c9\u5f97\u7acb\u4f4f\u7684\u60c5\u51b5\u80fd\u6709\u51e0\u6b21:\"))\na = 0\ncount = 0\ncount_f = 0\ncount_w = 0\ncoin = &#91;\"\u5b57\",\"\u82b1\",\"\u7acb\u4f4f\u4e86\"]\ncount_s = 0\nwhile count&lt;=1000:\n    count = count+1\n    a = random.randint(1,1000)\n    if a>(1000-b):\n        count_s +=1\n    elif a>=(1000-b)\/2:\n        print(\"\u7b2c\",count,\"\u6b21: \",coin&#91;0])\n        count_w = count_w+1\n    else:\n        print(\"\u7b2c\",count,\"\u6b21: \",coin&#91;1])\n        count_f = count_f+1\n\n# print(\"\\n***\u606d\u559c\u4f60\uff01***\\n\",\"\u7b2c\",count,\"\u6b21: \u6295\u5e01\u7acb\u4f4f\u4e86\")\nprint(\"\u82b1\u51fa\u73b0\u4e86\uff1a\",count_f,\"\u6b21\u3002\")\nprint(\"\u5b57\u51fa\u73b0\u4e86\uff1a\",count_w,\"\u6b21\u3002\")\nprint(\"\u7acb\u51fa\u73b0\u4e86\uff1a\",count_s,\"\u6b21\u3002\")\nprint(\"\u6e38\u620f\u7ed3\u675f\")<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001random\u6a21\u5757\u53ef\u4ee5\u5f15\u5165\u968f\u673a\u6570 2\u3001\u968f\u673a\u6570\u7684\u4ea7\u751f\u662f\u76f8\u540c\u6982\u7387\u7684\u3002\u4f46\u662f\u5047\u5982\u5206\u522b\u5c06\u4e0d\u540c\u6570\u91cf\u7684\u968f\u673a\u6570\u5212\u5206\u5230\u4e3a\u4e00\u4e2a\u533a\u57df\uff0c\u4ea7\u751f\u67d0\u6570\u5728\u8be5\u533a\u57df\u7684\u6982\u7387\u5c06\u662f\u6570\u91cf\u4e4b\u548c\u3002\u533a\u57df\u8d8a\u5927\uff0c\u6982\u7387\u8d8a\u5927\u3002\u6b64\u4e3a\u6b65\u957f 3\u3001\u5229\u7528\u4e0d\u540c\u6b65\u957f\u4ee3\u8868\u4e0d\u540c\u6982\u7387\u7684\u7406\u5ff5\uff0c\u8bbe\u8ba1\u4e00\u4e2a\u6295\u5e01\u7684\u6e38\u620f\u3002\u7b97\u6cd5\u5982\u4e0b\uff1a 4\u3001\u6295\u5e01\u6e38\u620f\u7684\u65b0\u73a9\u6cd5\uff0c\u5728\u8bbe\u5b9a\u6982\u7387\u7684\u60c5\u51b5\u4e0b\uff0c\u89c2\u5bdf\u5b9e\u9645\u4f1a&hellip;<\/p>\n<p> <a class=\"more-link\" href=\"http:\/\/homeyk.com\/?p=83\">\u7ee7\u7eed\u9605\u8bfb<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,16],"_links":{"self":[{"href":"http:\/\/homeyk.com\/index.php?rest_route=\/wp\/v2\/posts\/83"}],"collection":[{"href":"http:\/\/homeyk.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/homeyk.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/homeyk.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/homeyk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=83"}],"version-history":[{"count":1,"href":"http:\/\/homeyk.com\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":151,"href":"http:\/\/homeyk.com\/index.php?rest_route=\/wp\/v2\/posts\/83\/revisions\/151"}],"wp:attachment":[{"href":"http:\/\/homeyk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/homeyk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/homeyk.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}