【发布时间】:2021-07-19 04:16:23
【问题描述】:
Python 学习者。处理每月定期存款,利息问题。除了在这个假设中,我被要求每 6 个月加薪一次。我在比预期更少的几个月内达到了目标数量。
目前正在使用 % 函数和 += 函数
annual_salary = float(input("What is your expected Income? "))
portion_saved = float(input("What percentage of your income you expect to save? "))
total_cost = float(input("what is the cost of your dream home? "))
semi_annual_raise = float(input("Enter your expected raise, as a decimal "))
monthly_salary = float(annual_salary/12)
monthly_savings = monthly_salary * portion_saved
down_payment= total_cost*.25
savings = 0
for i in range(300):
savings = monthly_savings*(((1+.04/12)**i) - 1)/(.04/12)
if float(savings) >= down_payment:
break
if i % 6 == 0 :
monthly_salary += monthly_salary * .03
monthly_savings = monthly_salary * portion_saved
【问题讨论】:
-
您的预期结果是什么。还有什么'n'
-
monthly_savings 值是多少,r 是多少,您预计需要多少个月?
-
在 115 个月而不是 142 个月内达到了储蓄目标。在原始帖子中添加了上下文。谢谢。
-
你应该考虑在第一个月加薪吗?当 'i' 为 0 时,monthly_salary 将被更新。 Range(1, 301) 会解决这个问题。