如何使用 while 循环将值每月增加 5%?

How can I increase a value by 5% monthly using a while loop?

我正在尝试获取初始余额并每月将价值增加 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

您永远不会在循环中更改 balance_interest

你打算用 *(counter/counter) 做什么?这只是乘以 1.0,即 no-op.

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

更好的是,因为您知道要迭代多少次,所以使用 for:

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

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