{"id":1270,"date":"2019-10-02T20:44:07","date_gmt":"2019-10-02T12:44:07","guid":{"rendered":"https:\/\/jackyu.cn\/?p=1270"},"modified":"2020-08-31T11:57:57","modified_gmt":"2020-08-31T03:57:57","slug":"python-three-in-one-method","status":"publish","type":"post","link":"https:\/\/jackyu.cn\/algorithm\/python-three-in-one-method\/","title":{"rendered":"Python \u4e09\u4f4d\u4e00\u5e76\u6cd5"},"content":{"rendered":"<div class=\"nc-light-gallery\">\n<p>\u8fd9\u4e24\u5929\u5e2e\u540c\u5b66\u89e3\u4e86\u4e00\u4e9b\u9898\u76ee\uff0c\u8fd9\u91cc\u603b\u7ed3\u4e00\u4e0b\u7b97\u6cd5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">0x00 \u9898\u76ee<\/h2>\n\n\n\n<p>\u8bf7\u5199\u4e00\u4e2a Python \u7a0b\u5e8f\u5b9e\u73b0\u5b9e\u6570\u7684\u300c\u4e09\u4f4d\u4e00\u5e76\u6cd5\u300d\u4e0e\u300c\u56db\u4f4d\u4e00\u5e76\u6cd5\u300d\u3002\u8f93\u5165\u4e00\u4e2a\u516b\u8fdb\u5236\u5c0f\u6570\uff0c\u5229\u7528\u4e09\u4f4d\u4e00\u5e76\u6cd5\u5c06\u5176\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236\u5b9e\u6570\uff0c\u5e76\u8f93\u51fa\uff0c\u518d\u5229\u7528\u56db\u4f4d\u4e00\u5e76\u6cd5\u5c06\u4e0a\u4e00\u6b65\u5f97\u5230\u7684\u4e8c\u8fdb\u5236\u5b9e\u6570\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u5b9e\u6570\uff0c\u5e76\u8f93\u51fa\u3002e.g. \u8f93\u5165 2.04(8) \u8f93\u51fa 010.00100\uff082) \u548c 2.1\uff0816\uff09\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">0x01.\u77e5\u8bc6\u50a8\u5907<\/h2>\n\n\n\n<p>\u4e8c\u8fdb\u5236\u4e0e\u516b\u8fdb\u5236\u6570\u4e4b\u95f4\u7684\u5bf9\u5e94\u5173\u7cfb<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>\u4e8c\u8fdb\u5236\u6570<\/td><td>\u516b\u8fdb\u5236\u6570<\/td><\/tr><tr><td>000<\/td><td>0<\/td><\/tr><tr><td>001<\/td><td>1<\/td><\/tr><tr><td>010<\/td><td>2<\/td><\/tr><tr><td>011<\/td><td>3<\/td><\/tr><tr><td>100<\/td><td>4<\/td><\/tr><tr><td>101<\/td><td>5<\/td><\/tr><tr><td>110<\/td><td>6<\/td><\/tr><tr><td>111<\/td><td>7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u516b\u8fdb\u5236\u8f6c\u4e8c\u8fdb\u5236\u7684\u65b9\u6cd5\u662f\u4e09\u4f4d\u4e00\u5e76\u6cd5\u7684\u9006\u7528<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>\u516b\u8fdb\u5236\u6570<\/td><td>1<\/td><td>6<\/td><td>.<\/td><td>7<\/td><td>1<\/td><\/tr><tr><td>\u4e8c\u8fdb\u5236\u6570<\/td><td>001<\/td><td>110<\/td><td>.<\/td><td>111<\/td><td>001<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4e8c\u8fdb\u5236\u8f6c\u5316\u4e3a\u5341\u8fdb\u5236\u7684\u65b9\u6cd5\u662f\uff0c\u4e09\u4f4d\u4e00\u5e76\u6cd5<\/p>\n\n\n\n<p>\u4e3e\u4e2a\u6817\u5b50 010.000100(2) \u7684\u8f6c\u5316\uff0c\u4ee5\u5c0f\u6570\u70b9\u4e3a\u754c\uff0c\u6574\u6570\u548c\u5c0f\u6570\u90e8\u5206\u5185\u6bcf\u4e09\u4f4d\u6570\u4e3a\u4e00\u7ec4\u8fdb\u884c\u5206\u7ec4\u8fdb\u884c\u8f6c\u5316\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>\u4e8c\u8fdb\u5236\u6570<\/td><td>010<\/td><td>.<\/td><td>000<\/td><td>100<\/td><\/tr><tr><td>\u516b\u8fdb\u5236\u6570<\/td><td>2<\/td><td>.<\/td><td>0<\/td><td>4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u90a3\u5982\u679c\u5206\u7ec4\u65f6\u65e0\u6cd5\u51d1\u8db3\u4e09\u4f4d\uff0c\u5219\u9700\u8981\u8fdb\u884c\u8865\u4f4d<\/p>\n\n\n\n<p>\u4e3e\u4e2a\u6817\u5b50 1010.0001001(2) \u7684\u8f6c\u5316\uff0c\u5bf9\u6574\u6570\u90e8\u5206\uff0c\u5728\u6700\u5de6\u8fb9\u8865\u51450\uff0c\u5bf9\u4e8e\u5c0f\u6570\u90e8\u5206\uff0c\u5728\u6700\u53f3\u8fb9\u8865\u51450\uff0c\u5373\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>\u4e8c\u8fdb\u5236<\/td><td>001<\/td><td>010<\/td><td>.<\/td><td>000<\/td><td>100<\/td><td>100<\/td><\/tr><tr><td>\u516b\u8fdb\u5236<\/td><td>1<\/td><td>2<\/td><td>.<\/td><td>0<\/td><td>4<\/td><td>4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">0x02 Python \u7684\u5b9e\u73b0<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># coding=utf-8\n\nprint('\u8bf7\u8f93\u5165\u4e00\u4e2a\u516b\u8fdb\u5236\u5c0f\u6570:')\noct_num = input()\nbinary = ''\nis_minus = False\n# \u4e09\u4f4d\u4e00\u5e76\u6cd5\u9006\u7528: 8\u8fdb\u5236\u5c0f\u6570\u8f6c2\u8fdb\u5236\u5c0f\u6570\nfor o in oct_num:\n    if o == '.':\n        binary += '.'\n    elif o == '-':\n        # \u5904\u7406\u8d1f\u6570\n        binary += ''\n        is_minus = True\n    else:\n        binary += format(int(o), '03b') # \u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0c\u5f3a\u5236\u5bbd\u5ea6\u4e3a3\u5b57\u8282\n\n# \u8d1f\u6570\u5904\u7406\nsym = '-' if is_minus is True else ''\n\nprint(sym + binary)<\/code><\/pre>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e24\u5929\u5e2e\u540c\u5b66\u89e3\u4e86\u4e00\u4e9b\u9898\u76ee\uff0c\u8fd9\u91cc\u603b\u7ed3\u4e00\u4e0b\u7b97\u6cd5\u3002 0x00 \u9898\u76ee \u8bf7\u5199\u4e00\u4e2a Python \u7a0b\u5e8f\u5b9e\u73b0\u5b9e\u6570\u7684\u300c\u4e09\u4f4d\u4e00\u5e76 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1683,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[92],"tags":[],"special":[],"class_list":["post-1270","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-algorithm"],"modified_by":"Jacky","_links":{"self":[{"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/posts\/1270","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/comments?post=1270"}],"version-history":[{"count":12,"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/posts\/1270\/revisions"}],"predecessor-version":[{"id":1686,"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/posts\/1270\/revisions\/1686"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/media\/1683"}],"wp:attachment":[{"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/media?parent=1270"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/categories?post=1270"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/tags?post=1270"},{"taxonomy":"special","embeddable":true,"href":"https:\/\/jackyu.cn\/wp-json\/wp\/v2\/special?post=1270"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}