首页 > 解决方案 > 如何使用 while 循环每月将值增加 5%?

问题描述

我正在尝试获取起始余额并每月将值增加 5%。然后我想在下个月将这个新的平衡反馈到方程式中。我尝试使用 while 循环来做到这一点,但它似乎并没有重新输入新的平衡。

我使用 60 个月(5 年)的公式,但这可以改变

counter = 1
balance = 1000
balance_interest = balance * .05

while counter <= 60:
    new_monthly_balance = (balance + balance_interest)*(counter/counter)
    print(new_monthly_balance)
    balance = new_monthly_balance
    counter += 1

标签: pythonfinance

解决方案


你永远不会改变balance_interest循环。

你打算做*(counter/counter)什么?这只是乘以 1.0,这是一个空操作。

while counter <= 60:
    balance *= 1.05
    print(balance)
    counter += 1

更好的是,既然您知道要迭代多少次,请使用 a for

for month in range(60):
    balance *= 1.05
    print(balance)

顺便说一句,什么样的金融每月有 5% 的持续增长???


推荐阅读