{"id":275,"date":"2025-10-10T11:16:18","date_gmt":"2025-10-10T03:16:18","guid":{"rendered":"http:\/\/www.pyteam.cn\/?p=275"},"modified":"2025-10-10T11:16:19","modified_gmt":"2025-10-10T03:16:19","slug":"%e7%bb%83%e4%b9%a02%ef%bc%9a%e6%8a%95%e8%b5%84%e7%bf%bb%e5%80%8d%e8%ae%a1%e7%ae%97-8-7","status":"publish","type":"post","link":"http:\/\/www.pyteam.cn\/index.php\/2025\/10\/10\/%e7%bb%83%e4%b9%a02%ef%bc%9a%e6%8a%95%e8%b5%84%e7%bf%bb%e5%80%8d%e8%ae%a1%e7%ae%97-8-7\/","title":{"rendered":"\u7ec3\u4e602\uff1a\u6295\u8d44\u7ffb\u500d\u8ba1\u7b97 8.7"},"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>money = 10000  # \u521d\u59cb\u672c\u91d1\ntarget = money * 2  # \u76ee\u6807\u91d1\u989d\nyears = 0  # \u5e74\u6570\n\nwhile money &lt; target:\n    money = money * 1.05  # \u6bcf\u5e74\u589e\u957f5%\n    years = years + 1\n    print(f\"\u7b2c{years}\u5e74\uff0c\u8d44\u4ea7\u4e3a\uff1a{money:.2f}\u5143\")\n\nprint(f\"\u9700\u8981{years}\u5e74\u8d44\u4ea7\u53ef\u4ee5\u7ffb\u500d\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\">money <\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">10000<\/span><span style=\"color: #90A4AE\">  <\/span><span style=\"color: #90A4AE; font-style: italic\"># \u521d\u59cb\u672c\u91d1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">target <\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #90A4AE\"> money <\/span><span style=\"color: #39ADB5\">*<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">2<\/span><span style=\"color: #90A4AE\">  <\/span><span style=\"color: #90A4AE; font-style: italic\"># \u76ee\u6807\u91d1\u989d<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">years <\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">0<\/span><span style=\"color: #90A4AE\">  <\/span><span style=\"color: #90A4AE; font-style: italic\"># \u5e74\u6570<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #39ADB5; font-style: italic\">while<\/span><span style=\"color: #90A4AE\"> money <\/span><span style=\"color: #39ADB5\">&lt;<\/span><span style=\"color: #90A4AE\"> target<\/span><span style=\"color: #39ADB5\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    money <\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #90A4AE\"> money <\/span><span style=\"color: #39ADB5\">*<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">1.05<\/span><span style=\"color: #90A4AE\">  <\/span><span style=\"color: #90A4AE; font-style: italic\"># \u6bcf\u5e74\u589e\u957f5%<\/span><\/span>\n<span class=\"line\"><span style=\"color: #90A4AE\">    years <\/span><span style=\"color: #39ADB5\">=<\/span><span style=\"color: #90A4AE\"> years <\/span><span style=\"color: #39ADB5\">+<\/span><span style=\"color: #90A4AE\"> <\/span><span style=\"color: #F76D47\">1<\/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;\u7b2c<\/span><span style=\"color: #F76D47\">{<\/span><span style=\"color: #6182B8\">years<\/span><span style=\"color: #F76D47\">}<\/span><span style=\"color: #91B859\">\u5e74\uff0c\u8d44\u4ea7\u4e3a\uff1a<\/span><span style=\"color: #F76D47\">{<\/span><span style=\"color: #6182B8\">money<\/span><span style=\"color: #9C3EDA\">:.2f<\/span><span style=\"color: #F76D47\">}<\/span><span style=\"color: #91B859\">\u5143&quot;<\/span><span style=\"color: #39ADB5\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6182B8\">print<\/span><span style=\"color: #39ADB5\">(<\/span><span style=\"color: #9C3EDA\">f<\/span><span style=\"color: #91B859\">&quot;\u9700\u8981<\/span><span style=\"color: #F76D47\">{<\/span><span style=\"color: #6182B8\">years<\/span><span style=\"color: #F76D47\">}<\/span><span style=\"color: #91B859\">\u5e74\u8d44\u4ea7\u53ef\u4ee5\u7ffb\u500d\u3002&quot;<\/span><span style=\"color: #39ADB5\">)<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":103,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,5],"tags":[],"class_list":["post-275","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-while","category-5"],"views":178,"_links":{"self":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/275","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=275"}],"version-history":[{"count":1,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/275\/revisions"}],"predecessor-version":[{"id":276,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/275\/revisions\/276"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media\/103"}],"wp:attachment":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media?parent=275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/categories?post=275"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/tags?post=275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}