Input: 1000, 0.07, 25 Output: 5427.43
Compound interest is when interest on a loan or investment is added back to the loan or investment. So it's like interest on interest! Compounding leads to exponential growth so it makes your investments grow big over time but also makes it much harder to pay off predatory loans and credit card debt.
If you start with an amount of money $m$ and the compound interest is calculated once a year with interest rate $r$ (as a fraction between 0 and 1) then after $n$ years you end up with a new amount $M$ given by $$ M = m (1 + r)^n $$
Submit some code with a function compound_interest(m, r, n) that computes the final amount $M$ after starting with an amount $m$ compounded yearly at a rate $r$ for $n$ years.
Input: Starting amount $m$, rate $r$, and number of years $n$.
Output: Final amount $M$.
|Function||compound_interest(m, r, n)|
You must be logged in to view your submissions.
Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able see a discussion thread below. Would be nice if you don't post solutions in there but if you do then please organize and document your code well so others can learn from it.