{"id":125,"date":"2025-10-09T16:31:07","date_gmt":"2025-10-09T08:31:07","guid":{"rendered":"http:\/\/www.pyteam.cn\/?p=125"},"modified":"2025-10-10T10:05:56","modified_gmt":"2025-10-10T02:05:56","slug":"%e6%95%99%e6%a1%88%ef%bc%9a%e6%b1%82%e8%a7%a3%e4%b8%80%e5%85%83%e4%b8%80%e6%ac%a1%e6%96%b9%e7%a8%8b","status":"publish","type":"post","link":"http:\/\/www.pyteam.cn\/index.php\/2025\/10\/09\/%e6%95%99%e6%a1%88%ef%bc%9a%e6%b1%82%e8%a7%a3%e4%b8%80%e5%85%83%e4%b8%80%e6%ac%a1%e6%96%b9%e7%a8%8b\/","title":{"rendered":"\u6559\u6848\uff1a\u6c42\u89e3\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b"},"content":{"rendered":"\n<p><strong>\u6559\u6848\u57fa\u672c\u4fe1\u606f<\/strong><\/p>\n\n\n\n<p><strong>\u8bfe\u7a0b\u540d\u79f0<\/strong>\uff1aPython\u7f16\u7a0b\u7b2c\u516d\u8bfe \u6c42\u89e3\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b<br><strong>\u6388\u8bfe\u5bf9\u8c61<\/strong>\uff1a\u7f16\u7a0b\u96f6\u57fa\u7840\u521d\u5b66\u8005<br><strong>\u8bfe\u65f6\u5b89\u6392<\/strong>\uff1a45\u5206\u949f<br><strong>\u6559\u5b66\u5f62\u5f0f<\/strong>\uff1a\u7406\u8bba\u8bb2\u89e3 + \u5b9e\u8df5\u64cd\u4f5c<\/p>\n\n\n\n<p><strong>\u4e00\u3001 \u6559\u5b66\u76ee\u6807<\/strong><\/p>\n\n\n\n<p><strong>\u77e5\u8bc6\u4e0e\u6280\u80fd\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6570\u5b66\u77e5\u8bc6\uff1a<\/strong>\u6df1\u5165\u7406\u89e3\u4e00\u5143\u4e00\u6b21\u65b9\u7a0bax + b = 0\u7684\u89e3\u7684\u4e09\u79cd\u60c5\u51b5\uff08\u552f\u4e00\u89e3\u3001\u65e0\u89e3\u3001\u65e0\u7a77\u591a\u89e3\uff09\u4e0e\u7cfb\u6570a,b\u7684\u5173\u7cfb\u3002<\/li>\n\n\n\n<li><strong>\u7f16\u7a0b\u77e5\u8bc6\uff1a<\/strong><span style=\"color: initial;\">\u5de9\u56fa\u00a0if-elif-else\u00a0\u591a\u5206\u652f\u9009\u62e9\u7ed3\u6784\u3002<\/span><span style=\"color: initial;\">\u5b66\u4e60\u5982\u4f55\u5904\u7406\u6d6e\u70b9\u6570\u8ba1\u7b97\u4e2d\u53ef\u80fd\u5b58\u5728\u7684\u7cbe\u5ea6\u95ee\u9898\u3002<\/span><\/li>\n\n\n\n<li>\u7efc\u5408\u8fd0\u7528\u53d8\u91cf\u3001\u8f93\u5165\u8f93\u51fa\u548c\u6761\u4ef6\u5224\u65ad\u89e3\u51b3\u590d\u6742\u95ee\u9898\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\u8fc7\u7a0b\u4e0e\u65b9\u6cd5\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u7ecf\u5386\u4ece\u6570\u5b66\u5b9a\u7406\u5230\u7a0b\u5e8f\u7b97\u6cd5\u7684\u5b8c\u6574\u8f6c\u5316\u8fc7\u7a0b\uff0c\u57f9\u517b\u8ba1\u7b97\u601d\u7ef4\u548c\u903b\u8f91\u63a8\u7406\u80fd\u529b\u3002<\/li>\n\n\n\n<li>\u901a\u8fc7\u7f16\u7a0b\u5b9e\u73b0\u6570\u5b66\u95ee\u9898\u7684\u5206\u7c7b\u8ba8\u8bba\uff0c\u4f53\u9a8c\u8ba1\u7b97\u673a\u5728\u89e3\u51b3\u89c4\u5219\u660e\u786e\u95ee\u9898\u4e0a\u7684\u9ad8\u6548\u6027\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\u60c5\u611f\u6001\u5ea6\u4e0e\u4ef7\u503c\u89c2\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u611f\u53d7\u7528\u7f16\u7a0b\u89e3\u51b3\u6570\u5b66\u95ee\u9898\u7684\u5a01\u529b\uff0c\u589e\u5f3a\u5b66\u4e60\u5174\u8da3\u548c\u81ea\u4fe1\u5fc3\u3002<\/li>\n\n\n\n<li>\u57f9\u517b\u4e25\u8c28\u3001\u5168\u9762\u7684\u601d\u7ef4\u4e60\u60ef\uff0c\u7406\u89e3\u8003\u8651\u95ee\u9898\u6240\u6709\u8fb9\u754c\u60c5\u51b5\u7684\u91cd\u8981\u6027\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\u4e8c\u3001 \u6559\u5b66\u91cd\u70b9\u4e0e\u96be\u70b9<\/strong><\/p>\n\n\n\n<p><strong>\u6559\u5b66\u91cd\u70b9\uff1a<\/strong>\u5206\u6790\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b\u89e3\u7684\u4e09\u79cd\u60c5\u51b5\uff0c\u5e76\u8f6c\u5316\u4e3aif-elif-else\u5206\u652f\u7ed3\u6784\u3002<\/p>\n\n\n\n<p><strong>\u6559\u5b66\u96be\u70b9\uff1a<\/strong>\u7406\u89e3a == 0\u65f6\u65b9\u7a0b\u7684\u89e3\u7531b\u51b3\u5b9a\uff1b\u5904\u7406\u6d6e\u70b9\u6570\u6bd4\u8f83\u65f6\u7684\u7cbe\u5ea6\u95ee\u9898\u3002<\/p>\n\n\n\n<p><strong>\u4e09\u3001 \u6559\u5b66\u51c6\u5907<\/strong><\/p>\n\n\n\n<p><strong>\u6559\u5e08\uff1a<\/strong>\u5b89\u88c5Python\u73af\u5883\u7684\u7535\u8111\u3001\u6295\u5f71\u8bbe\u5907\u3001\u6559\u5b66\u8bfe\u4ef6\u3002<\/p>\n\n\n\n<p><strong>\u5b66\u751f\uff1a<\/strong>\u7535\u8111\u5df2\u5b89\u88c5Python\u73af\u5883\uff0c\u5df2\u638c\u63e1if-elif-else\u7ed3\u6784\u548c\u57fa\u672c\u8fd0\u7b97\u7b26\u3002<\/p>\n\n\n\n<p><strong>\u56db\u3001 \u6559\u5b66\u8fc7\u7a0b<\/strong><\/p>\n\n\n\n<p><strong>\uff08\u4e00\uff09 \u95ee\u9898\u5bfc\u5165\u4e0e\u6570\u5b66\u5206\u6790\uff0810\u5206\u949f\uff09<\/strong><\/p>\n\n\n\n<p><strong>\u6559\u5e08\u6d3b\u52a8\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5199\u51fa\u4e00\u822c\u5f62\u5f0f\uff1aax + b = 0 (a, b \u4e3a\u5e38\u6570)\u3002<\/li>\n\n\n\n<li><span style=\"color: initial;\"><strong>\u63d0\u95ee\uff1a<\/strong>&#8220;\u8fd9\u4e2a\u65b9\u7a0b\u7684\u89e3\u662f\u4ec0\u4e48\uff1f\u662f\u4e0d\u662f\u6c38\u8fdc\u90fd\u662fx = -b\/a\uff1f&#8221; \u5f15\u5bfc\u5b66\u751f\u601d\u8003\u3002<\/span><\/li>\n\n\n\n<li><strong>\u5f15\u5bfc\u5b66\u751f\u8fdb\u884c\u6570\u5b66\u5206\u7c7b\u8ba8\u8bba\uff08\u677f\u4e66\u5173\u952e\u903b\u8f91\uff09\uff1a<\/strong><\/li>\n<\/ol>\n\n\n\n<p><strong>\u60c5\u51b5\u4e00\uff1a\u5f53&nbsp;<\/strong><strong>a \u2260 0<\/strong><strong>&nbsp;<\/strong><strong>\u65f6<\/strong><br>\u65b9\u7a0b\u6709<strong>\u552f\u4e00\u89e3<\/strong>\uff0c\u89e3\u4e3a&nbsp;x = -b \/ a\u3002<\/p>\n\n\n\n<p><strong>\u60c5\u51b5\u4e8c\uff1a\u5f53&nbsp;<\/strong><strong>a = 0<\/strong><strong>&nbsp;<\/strong><strong>\u65f6<\/strong>\uff0c\u9700\u8981\u8fdb\u4e00\u6b65\u5224\u65ad\uff1a<\/p>\n\n\n\n<p><strong>\u5b50\u60c5\u51b5\u4e00\uff1a<\/strong><strong>b \u2260 0<\/strong><br>\u65b9\u7a0b\u53d8\u4e3a&nbsp;0*x + b = 0&nbsp;=&gt;&nbsp;b = 0\u3002\u8fd9\u662f\u4e00\u4e2a<strong>\u77db\u76fe<\/strong>\u7684\u7b49\u5f0f\uff0c\u6240\u4ee5\u65b9\u7a0b<strong>\u65e0\u89e3<\/strong>\u3002<\/p>\n\n\n\n<p><strong>\u5b50\u60c5\u51b5\u4e8c\uff1a<\/strong><strong>b = 0<\/strong><br>\u65b9\u7a0b\u53d8\u4e3a&nbsp;0*x + 0 = 0&nbsp;=&gt;&nbsp;0 = 0\u3002\u8fd9\u662f\u4e00\u4e2a<strong>\u6c38\u6052\u6210\u7acb<\/strong>\u7684\u7b49\u5f0f\uff0c\u6240\u4ee5\u65b9\u7a0b\u6709<strong>\u65e0\u7a77\u591a\u89e3<\/strong>\uff08\u4efb\u4f55\u5b9e\u6570\u90fd\u662f\u89e3\uff09\u3002<\/p>\n\n\n\n<p><strong>\u5b66\u751f\u6d3b\u52a8\uff1a<\/strong>\u8ddf\u968f\u8001\u5e08\u56de\u987e\u6570\u5b66\u77e5\u8bc6\uff0c\u7406\u89e3\u5206\u7c7b\u8ba8\u8bba\u7684\u5b8c\u6574\u903b\u8f91\u94fe\u6761\u3002<\/p>\n\n\n\n<p><strong>\u8bbe\u8ba1\u610f\u56fe\uff1a<\/strong>\u5c06\u660e\u786e\u7684\u6570\u5b66\u903b\u8f91\u4f5c\u4e3a\u7f16\u7a0b\u7684\u57fa\u7840\uff0c\u8fd9\u662f\u89e3\u51b3\u95ee\u9898\u7684\u5173\u952e\u7b2c\u4e00\u6b65\u3002<\/p>\n\n\n\n<p><strong>\uff08\u4e8c\uff09 \u7b97\u6cd5\u8bbe\u8ba1\u4e0e\u96be\u70b9\u7a81\u7834\uff0810\u5206\u949f\uff09<\/strong><\/p>\n\n\n\n<p><strong>1. <\/strong><strong>\u5c06\u6570\u5b66\u903b\u8f91\u8f6c\u5316\u4e3a\u7a0b\u5e8f\u7b97\u6cd5<\/strong><\/p>\n\n\n\n<p><strong>\u6559\u5e08\u5f15\u5bfc\uff1a<\/strong>\u4e0a\u9762\u7684\u5206\u6790\u5c31\u50cf\u4e00\u4e2a\u51b3\u7b56\u6811\uff0c\u975e\u5e38\u9002\u5408\u7528&nbsp;if-elif-else&nbsp;\u7ed3\u6784\u6765\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p><strong>\u7ed8\u5236\u7a0b\u5e8f\u6d41\u7a0b\u56fe\uff08\u677f\u4e66\u6216\u6295\u5f71\uff09\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1006\" height=\"1024\" src=\"http:\/\/www.pyteam.cn\/wp-content\/uploads\/2025\/10\/\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b\u6c42\u89e3\u6d41\u7a0b\u56fe-1006x1024.png\" alt=\"\" class=\"wp-image-128\" style=\"width:491px;height:auto\" srcset=\"http:\/\/www.pyteam.cn\/wp-content\/uploads\/2025\/10\/\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b\u6c42\u89e3\u6d41\u7a0b\u56fe-1006x1024.png 1006w, http:\/\/www.pyteam.cn\/wp-content\/uploads\/2025\/10\/\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b\u6c42\u89e3\u6d41\u7a0b\u56fe-295x300.png 295w, http:\/\/www.pyteam.cn\/wp-content\/uploads\/2025\/10\/\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b\u6c42\u89e3\u6d41\u7a0b\u56fe-768x782.png 768w, http:\/\/www.pyteam.cn\/wp-content\/uploads\/2025\/10\/\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b\u6c42\u89e3\u6d41\u7a0b\u56fe-1509x1536.png 1509w, http:\/\/www.pyteam.cn\/wp-content\/uploads\/2025\/10\/\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b\u6c42\u89e3\u6d41\u7a0b\u56fe-2013x2048.png 2013w, http:\/\/www.pyteam.cn\/wp-content\/uploads\/2025\/10\/\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b\u6c42\u89e3\u6d41\u7a0b\u56fe-80x80.png 80w\" sizes=\"auto, (max-width: 1006px) 100vw, 1006px\" \/><\/figure>\n\n\n\n<p><strong>2. <\/strong><strong>\u96be\u70b9\u7a81\u7834\uff1a\u6d6e\u70b9\u6570\u7cbe\u5ea6\u95ee\u9898<\/strong><\/p>\n\n\n\n<p><strong>\u6559\u5e08\u8bb2\u89e3\uff1a<\/strong>\u5728\u8ba1\u7b97\u673a\u4e2d\uff0c\u6d6e\u70b9\u6570\uff08\u5c0f\u6570\uff09\u7684\u5b58\u50a8\u548c\u8ba1\u7b97\u53ef\u80fd\u5b58\u5728\u5fae\u5c0f\u7684\u8bef\u5dee\u3002\u76f4\u63a5\u5224\u65ada == 0\u53ef\u80fd\u4e0d\u53ef\u9760\u3002<\/p>\n\n\n\n<p><strong>\u4e3e\u4f8b\uff1a<\/strong>0.1 + 0.2\u7684\u7ed3\u679c\u5728Python\u4e2d\u4e0d\u662f\u7cbe\u786e\u76840.3\uff0c\u800c\u662f\u4e00\u4e2a\u975e\u5e38\u63a5\u8fd1\u7684\u6570\u3002<\/p>\n\n\n\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>\u5224\u65ad\u4e00\u4e2a\u6d6e\u70b9\u6570\u662f\u5426&#8221;\u7b49\u4e8e&#8221;0\uff0c\u6211\u4eec\u901a\u5e38\u5224\u65ad\u5b83\u7684<strong>\u7edd\u5bf9\u503c<\/strong>\u662f\u5426\u5c0f\u4e8e\u4e00\u4e2a\u975e\u5e38\u5c0f\u7684\u6570\uff08\u4f8b\u59821e-9\uff09\uff0c\u5982\u679c\u662f\uff0c\u6211\u4eec\u5c31\u8ba4\u4e3a\u5b83\u7b49\u4e8e0\u3002<\/p>\n\n\n\n<p><strong>\u5f15\u5165\u7edd\u5bf9\u503c\u51fd\u6570&nbsp;<\/strong><strong>abs()<\/strong>\uff1aabs(a) &lt; 1e-9&nbsp;\u8868\u793aa\u7684\u7edd\u5bf9\u503c\u5c0f\u4e8e0.000000001\uff0c\u53ef\u4ee5\u8ba4\u4e3aa\u662f0\u3002<\/p>\n\n\n\n<p><strong>\uff08\u4e09\uff09 \u4ee3\u7801\u5b9e\u73b0\u4e0e\u8303\u4f8b\u8bb2\u89e3\uff0815\u5206\u949f\uff09<\/strong><\/p>\n\n\n\n<p><strong>\u6559\u5e08\u5e26\u9886\u5b66\u751f\u7f16\u5199\u4ee3\u7801\uff1a<\/strong><\/p>\n\n\n\n<p>python<\/p>\n\n\n\n<p><em># <\/em><em>\u6c42\u89e3\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b ax + b = 0<\/em><\/p>\n\n\n\n<p><em># 1. <\/em><em>\u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u7cfb\u6570a\u548cb<\/em><\/p>\n\n\n\n<p>print(&#8220;\u8bf7\u8f93\u5165\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b ax + b = 0 \u7684\u7cfb\u6570\uff1a&#8221;)<\/p>\n\n\n\n<p>a = float(input(&#8220;a = &#8220;))<\/p>\n\n\n\n<p>b = float(input(&#8220;b = &#8220;))<\/p>\n\n\n\n<p><em># 2. <\/em><em>\u8bbe\u7f6e\u4e00\u4e2a\u975e\u5e38\u5c0f\u7684\u9608\u503c\uff0c\u7528\u4e8e\u5224\u65ad\u6d6e\u70b9\u6570\u662f\u5426\u4e3a0<\/em><\/p>\n\n\n\n<p>epsilon = 1e-9<\/p>\n\n\n\n<p><em># 3. <\/em><em>\u6839\u636e\u5206\u7c7b\u8ba8\u8bba\u7684\u903b\u8f91\u8fdb\u884c\u5224\u65ad<\/em><\/p>\n\n\n\n<p>if abs(a) &gt; epsilon:&nbsp; <em># <\/em><em>\u60c5\u51b51\uff1a a \u2260 0 (\u8003\u8651\u7cbe\u5ea6\u540e)<\/em><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; <em># <\/em><em>\u65b9\u7a0b\u6709\u552f\u4e00\u89e3<\/em><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; x = -b \/ a<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; <em># <\/em><em>\u683c\u5f0f\u5316\u8f93\u51fa\uff0c\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570<\/em><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; print(f&#8221;\u65b9\u7a0b\u6709\u552f\u4e00\u89e3\uff1ax = {x:.2f}&#8221;)<\/p>\n\n\n\n<p>elif abs(b) &gt; epsilon: <em># <\/em><em>\u60c5\u51b52\uff1a a \u2248 0 \u4f46 b \u2260 0<\/em><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; <em># <\/em><em>\u65b9\u7a0b\u65e0\u89e3<\/em><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; print(&#8220;\u65b9\u7a0b\u65e0\u89e3\u3002&#8221;)<\/p>\n\n\n\n<p>else: <em># <\/em><em>\u60c5\u51b53\uff1a a \u2248 0 \u4e14 b \u2248 0<\/em><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; <em># <\/em><em>\u65b9\u7a0b\u6709\u65e0\u7a77\u591a\u89e3<\/em><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; print(&#8220;\u65b9\u7a0b\u6709\u65e0\u7a77\u591a\u89e3\u3002&#8221;)<\/p>\n\n\n\n<p><strong>\u4ee3\u7801\u8bb2\u89e3\u8981\u70b9\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>float(input(&#8230;))\uff1a\u786e\u4fdd\u8f93\u5165\u88ab\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u3002\u3001<\/li>\n\n\n\n<li><span style=\"color: initial;\">epsilon = 1e-9\uff1a\u5b9a\u4e49\u7cbe\u5ea6\u9608\u503c\u3002<\/span><\/li>\n\n\n\n<li><span style=\"color: initial;\">if abs(a) > epsilon:\uff1a\u8fd9\u662f\u5224\u65ad\u00a0a\u00a0\u662f\u5426\u4e0d\u4e3a0\u7684<\/span><strong style=\"color: initial;\">\u5b89\u5168\u5199\u6cd5<\/strong><span style=\"color: initial;\">\u3002<\/span><\/li>\n\n\n\n<li><span style=\"color: initial;\">elif abs(b) > epsilon:\uff1a\u5f53\u00a0a\u00a0\u4e3a0\u65f6\uff0c\u5224\u65ad\u00a0b\u00a0\u662f\u5426\u4e0d\u4e3a0\u3002<\/span><\/li>\n\n\n\n<li><span style=\"color: initial;\">else:\uff1a\u5bf9\u5e94\u00a0a\u00a0\u548c\u00a0b\u00a0\u90fd\u8fd1\u4f3c\u4e3a0\u7684\u60c5\u51b5\u3002<\/span><\/li>\n\n\n\n<li>{x:.2f}\uff1a\u683c\u5f0f\u5316\u8f93\u51fa\uff0c\u5c06\u89e3\u00a0x\u00a0\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u66f4\u7f8e\u89c2\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\uff08\u56db\uff09 \u6d4b\u8bd5\u4e0e\u9a8c\u8bc1\uff085\u5206\u949f\uff09<\/strong><\/p>\n\n\n\n<p><strong>\u5e08\u751f\u5171\u540c\u6d4b\u8bd5\uff1a<\/strong>\u8fd0\u884c\u7a0b\u5e8f\uff0c\u8f93\u5165\u4ee5\u4e0b\u51e0\u7ec4\u5178\u578b\u7684(a, b)\u503c\uff0c\u9a8c\u8bc1\u7a0b\u5e8f\u7684\u6b63\u786e\u6027\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>(2, 4)\u00a0-> \u552f\u4e00\u89e3\u00a0x = -2\u00a0\uff08\u9a8c\u8bc1\u4e3b\u8981\u529f\u80fd\uff09<\/li>\n\n\n\n<li><span style=\"color: initial;\">(0, 5)\u00a0-> \u65e0\u89e3 \uff08\u9a8c\u8bc1\u8fb9\u754c\u60c5\u51b51\uff09<\/span><\/li>\n\n\n\n<li><span style=\"color: initial;\">(0, 0)\u00a0-> \u65e0\u7a77\u591a\u89e3 \uff08\u9a8c\u8bc1\u8fb9\u754c\u60c5\u51b52\uff09<\/span><\/li>\n\n\n\n<li><span style=\"color: initial;\">(0.0000000001, 1)\u00a0-> \u552f\u4e00\u89e3 \uff08\u867d\u5c0f\u4f46\u4e0d\u4e3a0\uff09<\/span><\/li>\n\n\n\n<li>(0.00000000001, 0.00000000001)\u00a0-> \u65e0\u7a77\u591a\u89e3 \uff08\u6781\u5c0f\u503c\u5224\u65ad\uff09<\/li>\n<\/ol>\n\n\n\n<p><strong>\uff08\u4e94\uff09 \u8bfe\u5802\u7ec3\u4e60\u4e0e\u62d3\u5c55\uff085\u5206\u949f\uff09<\/strong><\/p>\n\n\n\n<p><strong>\u7ec3\u4e60\uff1a\u6539\u8fdb\u8f93\u51fa<\/strong><\/p>\n\n\n\n<p><strong>\u4efb\u52a1\uff1a<\/strong>\u4fee\u6539\u7a0b\u5e8f\uff0c\u5f53\u65b9\u7a0b\u6709\u552f\u4e00\u89e3\u65f6\uff0c\u5982\u679c\u89e3\u662f\u6574\u6570\uff08\u5982&nbsp;x=2.00\uff09\uff0c\u5219\u8f93\u51fa\u6574\u6570\u5f62\u5f0f\uff08x=2\uff09\uff1b\u5982\u679c\u662f\u5c0f\u6570\uff0c\u5219\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\u3002<\/p>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong>\u4f7f\u7528int()\u8f6c\u6362\u548c\u6761\u4ef6\u5224\u65ad\u3002\u4f8b\u5982\uff1aif x == int(x):<\/p>\n\n\n\n<p>python<\/p>\n\n\n\n<p><em># <\/em><em>\u5728\u8f93\u51fa\u552f\u4e00\u89e3\u7684\u90e8\u5206\u8fdb\u884c\u4fee\u6539<\/em><\/p>\n\n\n\n<p>if abs(a) &gt; epsilon:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; x = -b \/ a<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; if abs(x &#8211; int(x)) &lt; epsilon:&nbsp; <em># <\/em><em>\u5224\u65adx\u662f\u5426\u4e3a\u6574\u6570<\/em><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(f&#8221;\u65b9\u7a0b\u6709\u552f\u4e00\u89e3\uff1ax = {int(x)}&#8221;)<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; else:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print(f&#8221;\u65b9\u7a0b\u6709\u552f\u4e00\u89e3\uff1ax = {x:.2f}&#8221;)<\/p>\n\n\n\n<p><strong>\uff08\u516d\uff09 \u8bfe\u5802\u5c0f\u7ed3\u4e0e\u4f5c\u4e1a\uff085\u5206\u949f\uff09<\/strong><\/p>\n\n\n\n<p><strong>\u5c0f\u7ed3\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6570\u5b66\u662f\u57fa\u7840\uff1a<\/strong>\u7f16\u7a0b\u524d\u5fc5\u987b\u7406\u6e05\u95ee\u9898\u7684\u6240\u6709\u903b\u8f91\u53ef\u80fd\u6027\uff08\u5206\u7c7b\u8ba8\u8bba\uff09\u3002<\/li>\n\n\n\n<li><strong style=\"color: initial;\">\u7b97\u6cd5\u662f\u6865\u6881\uff1a<\/strong><span style=\"color: initial;\">\u5c06\u6570\u5b66\u903b\u8f91\u8f6c\u5316\u4e3a\u6e05\u6670\u7684\u6b65\u9aa4\uff08\u6d41\u7a0b\u56fe\uff09\u3002<\/span><\/li>\n\n\n\n<li><strong style=\"color: initial;\">\u4ee3\u7801\u662f\u5de5\u5177\uff1a<\/strong><span style=\"color: initial;\">\u7528if-elif-else\u5b9e\u73b0\u5206\u652f\uff0c\u7528abs(a) &lt; epsilon\u5b89\u5168\u5730\u6bd4\u8f83\u6d6e\u70b9\u6570\u3002<\/span><\/li>\n\n\n\n<li><strong>\u6d4b\u8bd5\u5f88\u91cd\u8981\uff1a<\/strong>\u5fc5\u987b\u7528\u591a\u79cd\u60c5\u51b5\u9a8c\u8bc1\u7a0b\u5e8f\u7684\u6b63\u786e\u6027\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\u4f5c\u4e1a\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u57fa\u7840\u9898\uff1a<\/strong>\u5b8c\u5584\u672c\u8bfe\u7684\u7a0b\u5e8f\uff0c\u5b9e\u73b0\u8bfe\u5802\u7ec3\u4e60\u4e2d\u7684\u201c\u6574\u6570\u89e3\u4f18\u5316\u8f93\u51fa\u201d\u529f\u80fd\u3002<\/li>\n\n\n\n<li><strong>\u6311\u6218\u9898\uff1a<\/strong>\u7f16\u5199\u7a0b\u5e8f\u6c42\u89e3\u4e00\u5143\u4e8c\u6b21\u65b9\u7a0bax\u00b2 + bx + c = 0\u7684\u6839\uff0c\u5e76\u8003\u8651\u5b9e\u6570\u6839\u7684\u60c5\u51b5\uff08\u5224\u522b\u5f0f\u5927\u4e8e0\u3001\u7b49\u4e8e0\u3001\u5c0f\u4e8e0\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\u4e94\u3001 \u677f\u4e66\u8bbe\u8ba1<\/strong><\/p>\n\n\n\n<p><strong>\u4e3b\u6807\u9898\uff1a<\/strong>\u7f16\u7a0b\u6c42\u89e3\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b<\/p>\n\n\n\n<p><strong>\u6570\u5b66\u903b\u8f91\uff1a<\/strong><\/p>\n\n\n\n<p>a \u2260 0&nbsp;-&gt; \u552f\u4e00\u89e3&nbsp;x = -b\/a<\/p>\n\n\n\n<p>a = 0 \u4e14 b \u2260 0&nbsp;-&gt; \u65e0\u89e3<\/p>\n\n\n\n<p>a = 0 \u4e14 b = 0&nbsp;-&gt; \u65e0\u7a77\u591a\u89e3<\/p>\n\n\n\n<p><strong>\u7f16\u7a0b\u6838\u5fc3\uff1a<\/strong><\/p>\n\n\n\n<p>python<\/p>\n\n\n\n<p>if abs(a) &gt; 1e-9:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; <em># <\/em><em>\u552f\u4e00\u89e3<\/em><\/p>\n\n\n\n<p>elif abs(b) &gt; 1e-9:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; <em># <\/em><em>\u65e0\u89e3<\/em><\/p>\n\n\n\n<p>else:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; <em># <\/em><em>\u65e0\u7a77\u591a\u89e3<\/em><\/p>\n\n\n\n<p><strong>\u5173\u952e\u6280\u5de7\uff1a<\/strong>\u6d6e\u70b9\u6570\u7cbe\u5ea6&nbsp;epsilon\uff0c\u683c\u5f0f\u5316\u8f93\u51fa&nbsp;:.2f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6559\u6848\u57fa\u672c\u4fe1\u606f \u8bfe\u7a0b\u540d\u79f0\uff1aPython\u7f16\u7a0b\u7b2c\u516d\u8bfe \u6c42\u89e3\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b\u6388\u8bfe&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":79,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,4],"tags":[],"class_list":["post-125","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-10","category-4"],"views":110,"_links":{"self":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/comments?post=125"}],"version-history":[{"count":2,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":129,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/125\/revisions\/129"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media\/79"}],"wp:attachment":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media?parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}