我正试图获得一个起始余额,每月增加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发布于 2019-07-23 16:15:18
您不会在循环中更改balance_interest。
你打算用*(counter/counter)做什么?这只是乘以1.0,这是一个不操作。
while counter <= 60:
balance *= 1.05
print(balance)
counter += 1更好的是,因为您知道要迭代多少次,所以可以使用for
for month in range(60):
balance *= 1.05
print(balance)顺便说一句,什么样的金融每月持续增长5%?
https://stackoverflow.com/questions/57168295
复制相似问题