0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Compound Interest Formula - Python Code

Posted at

Compound Interest Formula

A = P \left(1 + \frac{r}{n}\right)^{nt}

where:
A is the final amount
P is the principal investment
r is the annual interest rate (as a decimal)
n is the number of times the interest is compounded per year
t is the time period in years

Python Code

compound_interest.py
def compound_interest(principal, rate, time, compound):
    amount = principal * (1 + (rate/compound)) ** (compound*time)
    return amount

principal = 1000
rate = 0.03
time = 5
compound = 8

amount = compound_interest(principal, rate, time, compound)

print("Compound interest after {} years: {:.2f}".format(time, amount))

# Output: Compound interest after 5 years: 1161.51
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?