{"id":942448,"date":"2024-12-26T22:06:11","date_gmt":"2024-12-26T14:06:11","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/942448.html"},"modified":"2024-12-26T22:06:13","modified_gmt":"2024-12-26T14:06:13","slug":"python-%e5%a6%82%e4%bd%95%e7%bb%93%e6%9d%9f%e8%be%93%e5%85%a5","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/942448.html","title":{"rendered":"python \u5982\u4f55\u7ed3\u675f\u8f93\u5165"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25080245\/9a979db6-4b16-4cb8-9c8c-aa7209fb5c24.webp\" alt=\"python \u5982\u4f55\u7ed3\u675f\u8f93\u5165\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u7ed3\u675f\u8f93\u5165\u6709\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528EOF\uff08End of File\uff09\u6807\u5fd7\u3001\u6307\u5b9a\u7279\u5b9a\u7684\u8f93\u5165\u6761\u4ef6\u3001\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u63a7\u5236\u3002<\/strong>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7\u68c0\u6d4b\u8f93\u5165\u6d41\u7684\u7ed3\u675f\u7b26\uff08\u5982EOF\uff09\u6216\u7279\u5b9a\u7684\u8f93\u5165\u6761\u4ef6\uff08\u5982\u7a7a\u884c\u6216\u7279\u5b9a\u5b57\u7b26\uff09\u6765\u5224\u65ad\u8f93\u5165\u7684\u7ed3\u675f\u3002\u5177\u4f53\u5b9e\u73b0\u65b9\u5f0f\u53d6\u51b3\u4e8e\u5e94\u7528\u573a\u666f\u548c\u8f93\u5165\u6765\u6e90\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\uff0c\u5373\u4f7f\u7528EOF\u6807\u5fd7\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5f53\u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u6355\u83b7EOFError\u5f02\u5e38\u6765\u68c0\u6d4b\u8f93\u5165\u7684\u7ed3\u675f\u3002EOF\uff0c\u5373\u6587\u4ef6\u7ed3\u675f\u7b26\uff0c\u901a\u5e38\u5728\u8f93\u5165\u6d41\u8017\u5c3d\u65f6\u7531\u7cfb\u7edf\u4ea7\u751f\u3002\u4f8b\u5982\uff0c\u5728Windows\u7cfb\u7edf\u4e2d\u53ef\u4ee5\u901a\u8fc7Ctrl+Z\u89e6\u53d1EOF\uff0c\u800c\u5728Unix\/Linux\u7cfb\u7edf\u4e2d\u5219\u53ef\u4ee5\u901a\u8fc7Ctrl+D\u6765\u5b9e\u73b0\u3002\u5f53\u7a0b\u5e8f\u6355\u83b7\u5230EOFError\u65f6\uff0c\u8868\u793a\u8f93\u5165\u5df2\u7ecf\u7ed3\u675f\uff0c\u53ef\u4ee5\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u5982\u4f55\u7ed3\u675f\u8f93\u5165\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528EOF\u6807\u5fd7\u7ed3\u675f\u8f93\u5165<\/p>\n<\/p>\n<ol>\n<li>\u6355\u83b7EOFError\u5f02\u5e38<\/li>\n<\/ol>\n<p><p>\u5728Python\u4e2d\uff0c\u5f53\u4f7f\u7528<code>input()<\/code>\u51fd\u6570\u4ece\u6807\u51c6\u8f93\u5165\u4e2d\u8bfb\u53d6\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u6355\u83b7EOFError\u6765\u68c0\u6d4b\u8f93\u5165\u7684\u7ed3\u675f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    while True:<\/p>\n<p>        data = input(&quot;Enter data (Ctrl+D to end): &quot;)<\/p>\n<p>        if not data:<\/p>\n<p>            break<\/p>\n<p>        print(f&quot;You entered: {data}&quot;)<\/p>\n<p>except EOFError:<\/p>\n<p>    print(&quot;Input ended.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u7528\u6237\u53ef\u4ee5\u4e0d\u65ad\u8f93\u5165\u6570\u636e\uff0c\u76f4\u5230\u89e6\u53d1EOF\uff08\u901a\u5e38\u4f7f\u7528Ctrl+D\u6216Ctrl+Z\uff09\u4e3a\u6b62\u3002\u7a0b\u5e8f\u6355\u83b7\u5230EOFError\u540e\uff0c\u4f1a\u8f93\u51fa\u201cInput ended.\u201d\uff0c\u8868\u793a\u8f93\u5165\u7ed3\u675f\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u8bfb\u53d6\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9<\/li>\n<\/ol>\n<p><p>\u5f53\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u65f6\uff0c\u901a\u5e38\u4f7f\u7528<code>read()<\/code>\u3001<code>readline()<\/code>\u6216<code>readlines()<\/code>\u65b9\u6cd5\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4f1a\u5728\u8bfb\u53d6\u5230\u6587\u4ef6\u672b\u5c3e\u65f6\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\u6216\u7a7a\u5217\u8868\uff0c\u4ece\u800c\u6807\u8bc6\u8f93\u5165\u7684\u7ed3\u675f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">with open(&#39;example.txt&#39;, &#39;r&#39;) as file:<\/p>\n<p>    while True:<\/p>\n<p>        line = file.readline()<\/p>\n<p>        if not line:<\/p>\n<p>            break<\/p>\n<p>        print(line.strip())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u7a0b\u5e8f\u4e0d\u65ad\u8bfb\u53d6\u6587\u4ef6\u4e2d\u7684\u6bcf\u4e00\u884c\uff0c\u76f4\u5230<code>readline()<\/code>\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\uff0c\u8868\u793a\u6587\u4ef6\u7ed3\u675f\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u6307\u5b9a\u7279\u5b9a\u7684\u8f93\u5165\u6761\u4ef6\u7ed3\u675f\u8f93\u5165<\/p>\n<\/p>\n<ol>\n<li>\u901a\u8fc7\u7279\u5b9a\u5b57\u7b26\u7ed3\u675f\u8f93\u5165<\/li>\n<\/ol>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u901a\u8fc7\u8ba9\u7528\u6237\u8f93\u5165\u7279\u5b9a\u7684\u5b57\u7b26\u6216\u5b57\u7b26\u4e32\u6765\u6807\u8bc6\u8f93\u5165\u7684\u7ed3\u675f\u3002\u4f8b\u5982\uff0c\u8ba9\u7528\u6237\u8f93\u5165&quot;END&quot;\u6765\u8868\u793a\u8f93\u5165\u7ed3\u675f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">while True:<\/p>\n<p>    data = input(&quot;Enter data (type &#39;END&#39; to finish): &quot;)<\/p>\n<p>    if data == &quot;END&quot;:<\/p>\n<p>        break<\/p>\n<p>    print(f&quot;You entered: {data}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5f53\u7528\u6237\u8f93\u5165&quot;END&quot;\u65f6\uff0c\u7a0b\u5e8f\u5c06\u7ec8\u6b62\u8f93\u5165\u5faa\u73af\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u901a\u8fc7\u7a7a\u884c\u7ed3\u675f\u8f93\u5165<\/li>\n<\/ol>\n<p><p>\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u901a\u8fc7\u8ba9\u7528\u6237\u8f93\u5165\u7a7a\u884c\u6765\u8868\u793a\u8f93\u5165\u7ed3\u675f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">while True:<\/p>\n<p>    data = input(&quot;Enter data (press Enter to finish): &quot;)<\/p>\n<p>    if not data:<\/p>\n<p>        break<\/p>\n<p>    print(f&quot;You entered: {data}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5f53\u7528\u6237\u6309\u4e0bEnter\u952e\u800c\u4e0d\u8f93\u5165\u4efb\u4f55\u5185\u5bb9\u65f6\uff0c\u7a0b\u5e8f\u5c06\u9000\u51fa\u8f93\u5165\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u63a7\u5236\u7ed3\u675f\u8f93\u5165<\/p>\n<\/p>\n<ol>\n<li>\u6355\u83b7\u81ea\u5b9a\u4e49\u5f02\u5e38<\/li>\n<\/ol>\n<p><p>\u5728\u67d0\u4e9b\u590d\u6742\u7684\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b9a\u4e49\u548c\u6355\u83b7\u81ea\u5b9a\u4e49\u5f02\u5e38\u6765\u63a7\u5236\u8f93\u5165\u7684\u7ed3\u675f\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class EndInputException(Exception):<\/p>\n<p>    pass<\/p>\n<p>def get_input():<\/p>\n<p>    try:<\/p>\n<p>        while True:<\/p>\n<p>            data = input(&quot;Enter data: &quot;)<\/p>\n<p>            if data == &quot;STOP&quot;:<\/p>\n<p>                r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se EndInputException<\/p>\n<p>            print(f&quot;You entered: {data}&quot;)<\/p>\n<p>    except EndInputException:<\/p>\n<p>        print(&quot;Input ended by custom exception.&quot;)<\/p>\n<p>get_input()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5f53\u7528\u6237\u8f93\u5165&quot;STOP&quot;\u65f6\uff0c\u7a0b\u5e8f\u629b\u51faEndInputException\u5f02\u5e38\uff0c\u4ece\u800c\u7ed3\u675f\u8f93\u5165\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u6355\u83b7\u5176\u4ed6\u5f02\u5e38<\/li>\n<\/ol>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u56e0\u4e3a\u8f93\u5165\u683c\u5f0f\u9519\u8bef\u6216\u5176\u4ed6\u539f\u56e0\u5f15\u53d1\u5f02\u5e38\u3002\u53ef\u4ee5\u901a\u8fc7\u6355\u83b7\u8fd9\u4e9b\u5f02\u5e38\u6765\u7ed3\u675f\u8f93\u5165\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    while True:<\/p>\n<p>        data = input(&quot;Enter a number (type &#39;exit&#39; to finish): &quot;)<\/p>\n<p>        if data.lower() == &quot;exit&quot;:<\/p>\n<p>            break<\/p>\n<p>        number = int(data)<\/p>\n<p>        print(f&quot;You entered: {number}&quot;)<\/p>\n<p>except ValueError:<\/p>\n<p>    print(&quot;Invalid input. Exiting.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5f53\u7528\u6237\u8f93\u5165\u975e\u6570\u5b57\u5b57\u7b26\u4e32\u65f6\uff0c\u7a0b\u5e8f\u6355\u83b7ValueError\u5e76\u7ec8\u6b62\u8f93\u5165\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5e94\u7528\u573a\u666f\u4e2d\u7684\u7ed3\u675f\u8f93\u5165\u7b56\u7565<\/p>\n<\/p>\n<ol>\n<li>\u7528\u6237\u4ea4\u4e92\u5f0f\u7a0b\u5e8f<\/li>\n<\/ol>\n<p><p>\u5728\u7528\u6237\u4ea4\u4e92\u5f0f\u7a0b\u5e8f\u4e2d\uff0c\u5efa\u8bae\u4f7f\u7528EOF\u6807\u5fd7\u6216\u7279\u5b9a\u8f93\u5165\u6761\u4ef6\u6765\u7ed3\u675f\u8f93\u5165\uff0c\u8fd9\u6837\u7528\u6237\u53ef\u4ee5\u6e05\u695a\u5730\u77e5\u9053\u5982\u4f55\u7ec8\u6b62\u8f93\u5165\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u6587\u4ef6\u5904\u7406\u7a0b\u5e8f<\/li>\n<\/ol>\n<p><p>\u5728\u5904\u7406\u6587\u4ef6\u8f93\u5165\u65f6\uff0c\u901a\u5e38\u4f9d\u8d56\u4e8e\u6587\u4ef6\u8bfb\u53d6\u65b9\u6cd5\u8fd4\u56de\u7684\u7a7a\u503c\u6765\u5224\u65ad\u8f93\u5165\u7ed3\u675f\u3002\u8fd9\u79cd\u65b9\u6cd5\u7b80\u6d01\u4e14\u9ad8\u6548\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u7f51\u7edc\u548c\u6d41\u5f0f\u6570\u636e\u5904\u7406<\/li>\n<\/ol>\n<p><p>\u5728\u5904\u7406\u7f51\u7edc\u6570\u636e\u6216\u6d41\u5f0f\u6570\u636e\u65f6\uff0c\u901a\u5e38\u9700\u8981\u66f4\u590d\u6742\u7684\u534f\u8bae\u6765\u786e\u5b9a\u8f93\u5165\u7684\u7ed3\u675f\u3002\u8fd9\u53ef\u80fd\u6d89\u53ca\u5230\u8bfb\u53d6\u7279\u5b9a\u7684\u6807\u8bc6\u7b26\u6216\u957f\u5ea6\u5b57\u6bb5\u6765\u5224\u65ad\u6570\u636e\u6d41\u7684\u7ed3\u675f\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u7ed3\u675f\u8f93\u5165\u7684\u65b9\u5f0f\u591a\u79cd\u591a\u6837\uff0c\u5177\u4f53\u7684\u9009\u62e9\u53d6\u51b3\u4e8e\u5e94\u7528\u573a\u666f\u548c\u7528\u6237\u9700\u6c42\u3002\u901a\u8fc7\u5408\u7406\u4f7f\u7528EOF\u6807\u5fd7\u3001\u7279\u5b9a\u8f93\u5165\u6761\u4ef6\u548c\u5f02\u5e38\u5904\u7406\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u63a7\u5236\u8f93\u5165\u7684\u7ed3\u675f\uff0c\u786e\u4fdd\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\u548c\u7528\u6237\u4f53\u9a8c\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u7528\u6237\u4ea4\u4e92\u5f0f\u7a0b\u5e8f\u8fd8\u662f\u590d\u6742\u7684\u6570\u636e\u6d41\u5904\u7406\u5e94\u7528\uff0c\u7406\u89e3\u548c\u7075\u6d3b\u8fd0\u7528\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u7ed3\u675f\u7528\u6237\u8f93\u5165\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>input()<\/code>\u51fd\u6570\u6765\u63a5\u6536\u7528\u6237\u8f93\u5165\u3002\u5982\u679c\u60f3\u8981\u7ed3\u675f\u8f93\u5165\uff0c\u53ef\u4ee5\u901a\u8fc7\u7279\u5b9a\u7684\u6761\u4ef6\u6765\u5b9e\u73b0\uff0c\u4f8b\u5982\u8f93\u5165\u4e00\u4e2a\u7279\u5b9a\u7684\u5b57\u7b26\uff08\u5982\u201cexit\u201d\u6216\u201cquit\u201d\uff09\u3002\u5b9e\u73b0\u793a\u4f8b\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">while True:\n    user_input = input(&quot;\u8bf7\u8f93\u5165\u5185\u5bb9\uff08\u8f93\u5165&#39;quit&#39;\u7ed3\u675f\uff09\uff1a&quot;)\n    if user_input.lower() == &#39;quit&#39;:\n        break\n    print(f&quot;\u60a8\u8f93\u5165\u7684\u5185\u5bb9\u662f\uff1a{user_input}&quot;)\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u7528\u6237\u8f93\u5165\u201cquit\u201d\u5c06\u7ed3\u675f\u5faa\u73af\uff0c\u4ece\u800c\u7ec8\u6b62\u8f93\u5165\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u591a\u884c\u8f93\u5165\u5e76\u7ed3\u675f\uff1f<\/strong><br \/>\u82e5\u9700\u8981\u63a5\u6536\u591a\u884c\u8f93\u5165\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u8f93\u5165\u7ed3\u675f\u65f6\u6309\u4e0b\u7279\u5b9a\u7684\u7ec4\u5408\u952e\u3002\u5177\u4f53\u64cd\u4f5c\u662f\uff1a\u5728\u8f93\u5165\u65f6\u6309\u4e0bCtrl+D\uff08Linux\u6216Mac\uff09\u6216Ctrl+Z\uff08Windows\uff09\uff0c\u8868\u793a\u8f93\u5165\u7ed3\u675f\u3002\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u5229\u7528\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u6765\u5904\u7406\u591a\u884c\u8f93\u5165\uff1a  <\/p>\n<pre><code class=\"language-python\">inputs = []\nprint(&quot;\u8bf7\u8f93\u5165\u591a\u884c\u5185\u5bb9\uff0c\u6309Ctrl+D\u6216Ctrl+Z\u7ed3\u675f\uff1a&quot;)\ntry:\n    while True:\n        line = input()\n        inputs.append(line)\nexcept EOFError:\n    print(&quot;\u8f93\u5165\u7ed3\u675f\u3002&quot;)\n    print(&quot;\u60a8\u8f93\u5165\u7684\u5185\u5bb9\u662f\uff1a&quot;)\n    print(&quot;\\n&quot;.join(inputs))\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u7528\u6237\u53ef\u4ee5\u65b9\u4fbf\u5730\u8f93\u5165\u591a\u884c\u5185\u5bb9\u5e76\u5728\u9700\u8981\u65f6\u7ed3\u675f\u8f93\u5165\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5904\u7406\u8f93\u5165\u5f02\u5e38\u4ee5\u786e\u4fdd\u7ed3\u675f\uff1f<\/strong><br \/>\u5728\u5904\u7406\u7528\u6237\u8f93\u5165\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u610f\u5916\u7684\u8f93\u5165\u6216\u9519\u8bef\u3002\u4e3a\u4e86\u786e\u4fdd\u7a0b\u5e8f\u80fd\u591f\u5728\u5f02\u5e38\u53d1\u751f\u65f6\u6b63\u5e38\u7ed3\u675f\uff0c\u53ef\u4ee5\u4f7f\u7528<code>try<\/code>\u548c<code>except<\/code>\u8bed\u53e5\u6765\u6355\u83b7\u5f02\u5e38\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">while True:\n    try:\n        user_input = input(&quot;\u8bf7\u8f93\u5165\u5185\u5bb9\uff08\u8f93\u5165&#39;quit&#39;\u7ed3\u675f\uff09\uff1a&quot;)\n        if user_input.lower() == &#39;quit&#39;:\n            print(&quot;\u8f93\u5165\u5df2\u7ed3\u675f\u3002&quot;)\n            break\n        print(f&quot;\u60a8\u8f93\u5165\u7684\u5185\u5bb9\u662f\uff1a{user_input}&quot;)\n    except Exception as e:\n        print(f&quot;\u53d1\u751f\u9519\u8bef\uff1a{e}\uff0c\u8bf7\u91cd\u8bd5\u3002&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u4ec5\u80fd\u5904\u7406\u7528\u6237\u8f93\u5165\uff0c\u8fd8\u80fd\u5728\u53d1\u751f\u5176\u4ed6\u9519\u8bef\u65f6\u4fdd\u8bc1\u7a0b\u5e8f\u80fd\u591f\u4f18\u96c5\u5730\u7ed3\u675f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u7ed3\u675f\u8f93\u5165\u6709\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528EOF\uff08End of File\uff09\u6807\u5fd7\u3001\u6307\u5b9a\u7279\u5b9a\u7684\u8f93\u5165\u6761\u4ef6\u3001\u4f7f\u7528\u5f02\u5e38\u5904\u7406 [&hellip;]","protected":false},"author":3,"featured_media":942449,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/942448"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=942448"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/942448\/revisions"}],"predecessor-version":[{"id":942450,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/942448\/revisions\/942450"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/942449"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=942448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=942448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=942448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}