{"id":224,"date":"2025-10-10T10:09:00","date_gmt":"2025-10-10T02:09:00","guid":{"rendered":"http:\/\/www.pyteam.cn\/?p=224"},"modified":"2025-10-10T10:09:31","modified_gmt":"2025-10-10T02:09:31","slug":"%e5%b0%86%e6%95%b0%e5%ad%a6%e9%80%bb%e8%be%91%e8%bd%ac%e5%8c%96%e4%b8%ba%e7%a8%8b%e5%ba%8f%e7%ae%97%e6%b3%952-6-1","status":"publish","type":"post","link":"http:\/\/www.pyteam.cn\/index.php\/2025\/10\/10\/%e5%b0%86%e6%95%b0%e5%ad%a6%e9%80%bb%e8%be%91%e8%bd%ac%e5%8c%96%e4%b8%ba%e7%a8%8b%e5%ba%8f%e7%ae%97%e6%b3%952-6-1\/","title":{"rendered":"\u5c06\u6570\u5b66\u903b\u8f91\u8f6c\u5316\u4e3a\u7a0b\u5e8f\u7b97\u6cd5  6.1"},"content":{"rendered":"\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:clamp(18px, 1.125rem, 27px);font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#90A4AE;--cbp-line-number-width:calc(2 * 0.6 * 1.125rem);line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#ededed;color:#8198a3\">Python<\/span><span role=\"button\" tabindex=\"0\" style=\"color:#90A4AE;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly># \u6c42\u89e3\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b ax + b = 0\n\n# 1. \u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u7cfb\u6570a\u548cb\nprint(\"\u8bf7\u8f93\u5165\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b ax + b = 0 \u7684\u7cfb\u6570\uff1a\")\na = float(input(\"a = \"))\nb = float(input(\"b = \"))\n\n# 2. \u8bbe\u7f6e\u4e00\u4e2a\u975e\u5e38\u5c0f\u7684\u9608\u503c\uff0c\u7528\u4e8e\u5224\u65ad\u6d6e\u70b9\u6570\u662f\u5426\u4e3a0\nepsilon = 1e-9\n\n# 3. \u6839\u636e\u5206\u7c7b\u8ba8\u8bba\u7684\u903b\u8f91\u8fdb\u884c\u5224\u65ad\nif abs(a) > epsilon:  # \u60c5\u51b51\uff1a a \u2260 0 (\u8003\u8651\u7cbe\u5ea6\u540e)\n    # \u65b9\u7a0b\u6709\u552f\u4e00\u89e3\n    x = -b \/ a\n    # \u683c\u5f0f\u5316\u8f93\u51fa\uff0c\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\n    print(f\"\u65b9\u7a0b\u6709\u552f\u4e00\u89e3\uff1ax = {x:.2f}\")\n    \nelif abs(b) > epsilon: # \u60c5\u51b52\uff1a a \u2248 0 \u4f46 b \u2260 0\n    # \u65b9\u7a0b\u65e0\u89e3\n    print(\"\u65b9\u7a0b\u65e0\u89e3\u3002\")\n    \nelse: # \u60c5\u51b53\uff1a a \u2248 0 \u4e14 b \u2248 0\n    # \u65b9\u7a0b\u6709\u65e0\u7a77\u591a\u89e3\n    print(\"\u65b9\u7a0b\u6709\u65e0\u7a77\u591a\u89e3\u3002\")<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-lighter\" style=\"background-color: #FAFAFA\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #90A4AE; font-style: italic\"># \u6c42\u89e3\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b ax + b = 0<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE; font-style: italic\"># 1. \u83b7\u53d6\u7528\u6237\u8f93\u5165\u7684\u7cfb\u6570a\u548cb<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6182B8\">print<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #39ADB5\">&quot;<\/span><span style=\"color: #91B859\">\u8bf7\u8f93\u5165\u4e00\u5143\u4e00\u6b21\u65b9\u7a0b ax + b = 0 \u7684\u7cfb\u6570\uff1a<\/span><span style=\"color: #39ADB5\">&quot;<\/span><span style=\"color: #39ADB5\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">a <\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #E2931D\">float<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #6182B8\">input<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #39ADB5\">&quot;<\/span><span style=\"color: #91B859\">a = <\/span><span style=\"color: #39ADB5\">&quot;<\/span><span style=\"color: #39ADB5\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">b <\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #E2931D\">float<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #6182B8\">input<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #39ADB5\">&quot;<\/span><span style=\"color: #91B859\">b = <\/span><span style=\"color: #39ADB5\">&quot;<\/span><span style=\"color: #39ADB5\">))<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE; font-style: italic\"># 2. \u8bbe\u7f6e\u4e00\u4e2a\u975e\u5e38\u5c0f\u7684\u9608\u503c\uff0c\u7528\u4e8e\u5224\u65ad\u6d6e\u70b9\u6570\u662f\u5426\u4e3a0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">epsilon <\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">1e-9<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE; font-style: italic\"># 3. \u6839\u636e\u5206\u7c7b\u8ba8\u8bba\u7684\u903b\u8f91\u8fdb\u884c\u5224\u65ad<\/span><\/span>\n<span class=\"line\"><span style=\"color: #39ADB5; font-style: italic\">if<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #6182B8\">abs<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #6182B8\">a<\/span><span style=\"color: #39ADB5\">)<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #39ADB5\">&gt;<\/span><span style=\"color: #90A4AE\"> epsilon<\/span><span style=\"color: #39ADB5\">:<\/span><span style=\"color: #90A4AE\">  <\/span><span style=\"color: #90A4AE; font-style: italic\"># \u60c5\u51b51\uff1a a \u2260 0 (\u8003\u8651\u7cbe\u5ea6\u540e)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    <\/span><span style=\"color: #90A4AE; font-style: italic\"># \u65b9\u7a0b\u6709\u552f\u4e00\u89e3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    x <\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #39ADB5\">-<\/span><span style=\"color: #90A4AE\">b <\/span><span style=\"color: #39ADB5\">\/<\/span><span style=\"color: #90A4AE\"> a<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    <\/span><span style=\"color: #90A4AE; font-style: italic\"># \u683c\u5f0f\u5316\u8f93\u51fa\uff0c\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    <\/span><span style=\"color: #6182B8\">print<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #9C3EDA\">f<\/span><span style=\"color: #91B859\">&quot;\u65b9\u7a0b\u6709\u552f\u4e00\u89e3\uff1ax = <\/span><span style=\"color: #F76D47\">{<\/span><span style=\"color: #6182B8\">x<\/span><span style=\"color: #9C3EDA\">:.2f<\/span><span style=\"color: #F76D47\">}<\/span><span style=\"color: #91B859\">&quot;<\/span><span style=\"color: #39ADB5\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #39ADB5; font-style: italic\">elif<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #6182B8\">abs<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #6182B8\">b<\/span><span style=\"color: #39ADB5\">)<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #39ADB5\">&gt;<\/span><span style=\"color: #90A4AE\"> epsilon<\/span><span style=\"color: #39ADB5\">:<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #90A4AE; font-style: italic\"># \u60c5\u51b52\uff1a a \u2248 0 \u4f46 b \u2260 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    <\/span><span style=\"color: #90A4AE; font-style: italic\"># \u65b9\u7a0b\u65e0\u89e3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    <\/span><span style=\"color: #6182B8\">print<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #39ADB5\">&quot;<\/span><span style=\"color: #91B859\">\u65b9\u7a0b\u65e0\u89e3\u3002<\/span><span style=\"color: #39ADB5\">&quot;<\/span><span style=\"color: #39ADB5\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #39ADB5; font-style: italic\">else<\/span><span style=\"color: #39ADB5\">:<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #90A4AE; font-style: italic\"># \u60c5\u51b53\uff1a a \u2248 0 \u4e14 b \u2248 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    <\/span><span style=\"color: #90A4AE; font-style: italic\"># \u65b9\u7a0b\u6709\u65e0\u7a77\u591a\u89e3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    <\/span><span style=\"color: #6182B8\">print<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #39ADB5\">&quot;<\/span><span style=\"color: #91B859\">\u65b9\u7a0b\u6709\u65e0\u7a77\u591a\u89e3\u3002<\/span><span style=\"color: #39ADB5\">&quot;<\/span><span style=\"color: #39ADB5\">)<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":87,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,5],"tags":[],"class_list":["post-224","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-10","category-5"],"views":90,"_links":{"self":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/224","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=224"}],"version-history":[{"count":2,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/224\/revisions"}],"predecessor-version":[{"id":226,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/224\/revisions\/226"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media\/87"}],"wp:attachment":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media?parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/categories?post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/tags?post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}