Reputation: 21
I am trying to figure out this question in python, I found the compound interest rate formula however, for me the biggest problem is how to add 50 dollars after each year after my money increased by interest rate
Principal(Starting amount) is: 100 USD
Yearly Interest rate: 10 percent
after each year-end, we add 50 USD.
How much our money will be after 3 years?
def compound_interest(p,r,n,t):
a = p * (1 + r/n)**t
return a
Thank you so much for your help from now!
Upvotes: 2
Views: 313
Reputation: 409
capital = 100
ir = 0.1
bonus = 50
def compound_interest(year, capital, ir, bonus):
if year == 0:
return capital
investment_return = (capital * ir) + bonus
return compound_interest(year - 1, capital + investment_return, ir, bonus)
print(compound_interest(0, capital, ir, bonus))
print(compound_interest(1, capital, ir, bonus))
print(compound_interest(2, capital, ir, bonus))
Upvotes: 2