{"id":29447,"date":"2024-11-25T08:59:22","date_gmt":"2024-11-25T00:59:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29447\/"},"modified":"2024-11-25T08:59:22","modified_gmt":"2024-11-25T00:59:22","slug":"python%e5%b0%8f%e7%a8%8b%e5%ba%8f-%e5%89%aa%e5%ad%90%ef%bc%8c%e7%9f%b3%e5%a4%b4%ef%bc%8c%e5%b8%83%e5%ae%9e%e4%be%8b%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29447\/","title":{"rendered":"python\u5c0f\u7a0b\u5e8f: \u526a\u5b50\uff0c\u77f3\u5934\uff0c\u5e03\u5b9e\u4f8b\u4ee3\u7801"},"content":{"rendered":"<p style=\"text-align: left\">\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4e3a\u5927\u5bb6\u8be6\u7ec6\u4ecb\u7ecd\u4e86python\u5c0f\u7a0b\u5e8f: \u526a\u5b50\uff0c\u77f3\u5934\uff0c\u5e03\u5b9e\u4f8b\u4ee3\u7801,\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u611f\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u4eec\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b<\/p>\n<p style=\"text-align: left\">\u95f2\u6765\u65e0\u4e8b\uff0c\u5199\u4e00\u4e2a\u5c0f\u7a0b\u5e8f\uff0c\u7ec3\u4e60\u4e00\u4e0bpython\uff0c\u54c8\u54c8\uff1a<\/p>\n<p style=\"text-align: left\">#!\/usr\/bin\/env python<\/p>\n<p style=\"text-align: left\">#coding:utf8<\/p>\n<p style=\"text-align: left\">#author : wangganyu188@163.com<\/p>\n<p style=\"text-align: left\">#date : 2014-09-11<\/p>\n<p style=\"text-align: left\">import random,sys<\/p>\n<p style=\"text-align: left\">#\u5b9a\u4e49\u77f3\u5934\u526a\u5b50\u5e03\u5b57\u5178<\/p>\n<p style=\"text-align: left\">dict = {<\/p>\n<p style=\"text-align: left\"> 1:&#8217;\u526a\u5b50&#8217;,<\/p>\n<p style=\"text-align: left\"> 2:&#8217;\u77f3\u5934&#8217;,<\/p>\n<p style=\"text-align: left\"> 3:&#8217;\u5e03&#8217;,<\/p>\n<p style=\"text-align: left\"> }<\/p>\n<p style=\"text-align: left\">for row in dict:<\/p>\n<p style=\"text-align: left\"> print &#8216;\u7f16\u53f7:&#8217;,row, &#8216;=&#8217;,dict[row]<\/p>\n<p style=\"text-align: left\">loop = True<\/p>\n<p style=\"text-align: left\">while loop:<\/p>\n<p style=\"text-align: left\"> print &#8216;\u60a8\u51fa\u4ec0\u4e48?&#8217;<\/p>\n<p style=\"text-align: left\"> you = raw_input(&#8216;\u8bf7\u8f93\u5165\u7f16\u53f7\u56de\u8f66:\u5982\u679c\u60f3\u9000\u51fa\u6e38\u620f\u6309q\u952e&#8217;).strip()<\/p>\n<p style=\"text-align: left\"> if you == &#8216;q&#8217;:<\/p>\n<p style=\"text-align: left\"> loop = False<\/p>\n<p style=\"text-align: left\"> print &#8220;\u53cb\u60c5\u63d0\u793a:\u6e38\u620f\u5c06\u9000\u51fa,\u8fce\u4e0b\u6b21\u518d\u73a9&#8221;<\/p>\n<p style=\"text-align: left\"> sys.exit()<\/p>\n<p style=\"text-align: left\"> else:<\/p>\n<p style=\"text-align: left\"> try:<\/p>\n<p style=\"text-align: left\"> dn = random.randint(1,3)<\/p>\n<p style=\"text-align: left\"> you = int(you)<\/p>\n<p style=\"text-align: left\"> if you &gt;= 1 and you <\/p>\n<p style=\"text-align: left\"> loop = True<\/p>\n<p style=\"text-align: left\"> print &#8216;\u4f60\u51fa:&#8217;,dict[you]<\/p>\n<p style=\"text-align: left\"> print &#8216;\u7535\u8111\u51fa:&#8217;,dict[dn]<\/p>\n<p style=\"text-align: left\"> print &#8216;\u7ed3\u679c:&#8217;,<\/p>\n<p style=\"text-align: left\"> if dn == you:<\/p>\n<p style=\"text-align: left\"> print &#8216;\u5e73\u5c40&#8217;<\/p>\n<p style=\"text-align: left\"> elif (you &gt; dn &nbsp;and you &#8211; dn == 1) or you + 2 == dn:<\/p>\n<p style=\"text-align: left\"> print &#8216;\u4f60\u80dc&#8217;<\/p>\n<p style=\"text-align: left\"> else:<\/p>\n<p style=\"text-align: left\"> print &#8216;\u7535\u8111\u80dc&#8217;<\/p>\n<p style=\"text-align: left\"> continue<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fpython\u5c0f\u7a0b\u5e8f: \u526a\u5b50\uff0c\u77f3\u5934\uff0c\u5e03\u5b9e\u4f8b\u4ee3\u7801\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4e3a\u5927\u5bb6\u8be6\u7ec6\u4ecb\u7ecd\u4e86python\u5c0f\u7a0b\u5e8f: \u526a\u5b50\uff0c\u77f3\u5934\uff0c\u5e03\u5b9e\u4f8b\u4ee3\u7801,\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u611f\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u4eec\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b \u95f2\u6765\u65e0\u4e8b\uff0c\u5199\u4e00\u4e2a\u5c0f\u7a0b\u5e8f\uff0c\u7ec3\u4e60\u4e00\u4e0bpython\uff0c\u54c8\u54c8\uff1a #!\/usr\/bin\/env python #coding:utf8 #author : wangganyu188@163.com #date : 2014-09-11 import random,sys #\u5b9a\u4e49\u77f3\u5934\u526a\u5b50\u5e03\u5b57\u5178 dict = { 1:&#8217;\u526a\u5b50&#8217;, 2:&#8217;\u77f3\u5934&#8217;, 3:&#8217;\u5e03&#8217;, } for row in dict: print &#8216;\u7f16\u53f7:&#8217;,row, &#8216;=&#8217;,dict[row] loop = True while loop: print &#8216;\u60a8\u51fa\u4ec0\u4e48?&#8217; you = raw_input(&#8216;\u8bf7\u8f93\u5165\u7f16\u53f7\u56de\u8f66:\u5982\u679c\u60f3\u9000\u51fa\u6e38\u620f\u6309q\u952e&#8217;).strip() if you == &#8216;q&#8217;: loop = False print &#8220;\u53cb\u60c5\u63d0\u793a:\u6e38\u620f\u5c06\u9000\u51fa,\u8fce\u4e0b\u6b21\u518d\u73a9&#8221; sys.exit() else: try: dn = random.randint(1,3) you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-29447","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=29447"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29447\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}