<p>问题是:</p>
<p>你已经从麻省理工学院毕业了,现在有一份很棒的工作!你搬到旧金山湾地区
决定开始存钱买房。由于湾区的房价很高,
你意识到,在你能负担得起贷款之前,你必须储蓄好几年
房子的付款。在A部分中,我们将确定你需要多长时间才能攒够钱
根据以下假设支付款项:</p>
<ol>
<li><p>把你梦想家园的成本称为“我”</p>
</li>
<li><p>将您迄今为止保存的金额称为“当前”。你从电流开始
节省0美元</p>
</li>
<li><p>假设您明智地投资您的当前储蓄,年回报率为r(换句话说,
在每个月底,您将收到额外的“流动*r/12”资金投入
你的储蓄——12是因为r是年利率)。假设你的投资赚了一大笔钱
回报率r=0.04(4%)</p>
</li>
<li><p>假设你的年薪是i</p>
</li>
<li><p>假设你每个月都要拿出一定数额的薪水来为自己的事业存钱
首期付款。称之为“p”。该变量应为十进制形式(即0.1
占百分之十</p>
</li>
<li><p>每个月底,你的储蓄将因投资回报而增加,
加上你月薪的百分比(年薪/12)。
写一个程序来计算你要花多少个月才能攒够足够的钱买房
付款您希望您的主要变量是浮点数,因此您应该将用户输入转换为浮点数。<br/>
您的程序应要求用户输入以下变量:</p>
</li>
<li><p>起始年薪(一)</p>
</li>
<li><p>要保存的工资部分(p)</p>
</li>
<li><p>梦想之家的成本(c)</p>
</li>
</ol>
<p>这是我的密码:</p>
<pre><code>i=int(input("Enter your annual salary:"))
p=float(input("Enter the percent of your salary to save, as a decimal:"))
c=float(input("Enter the cost of your dream home:"))
r=0
current=float(i*p*r/12)
for r in range(9999999):
if current<c:
current=current*(0.04)/12
else:
break
print("Number of months ="+ str( int(r)))
</code></pre>
<p>以下输入所需的正确输出为:</p>
<pre><code>Enter your annual salary: 120000
Enter the percent of your salary to save, as a decimal: .10
Enter the cost of your dream home: 1000000
Number of months: 1000
</code></pre>
<p>但我得到的结果是:</p>
<pre><code>Enter your annual salary:120000
Enter the percent of your salary to save, as a decimal:.10
Enter the cost of your dream home:1000000
Number of months =9999998
</code></pre>
<p>谁能告诉我为什么我错了吗</p>
<p>非常抱歉之前我上传了一个稍微不同的问题;
我现在已提出有关问题</p>