cmcrae1019
cmcrae1019

Reputation: 13

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

I'm attempting to take a starting balance and increase the value by 5% each month. I then want to feed this new balance back into the equation for the next month. I've attempted to do this using a while loop but it doesn't seem to be feeding the new balance back in.

I'm using 60 months (5 years) for the equation but this can be altered

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

Upvotes: 0

Views: 258

Answers (1)

Prune
Prune

Reputation: 77857

You never change balance_interest in the loop.

What do you intend to do with *(counter/counter)? This merely multiplies by 1.0, which is a no-op.

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

Better yet, since you know how many times you want to iterate, use a for:

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

BTW, just what sort of finance has a constant 5% monthly increase???

Upvotes: 4

Related Questions