Introducing how to perform compound interest calculations for investments using the Python programming language.


The value when starting with 600,000 yen and continuing with 10% annual profit for 10 years
>>> compound_interest(600000, 10, 10)
1556245.4760600014
The value when starting with 600,000 yen and continuing with 10% annual profit for 20 years
>>> compound_interest(600000, 10, 20)
4036499.9695953666
Code
def compound_interest(principle, rate, time):
print( principle * (pow((1 + rate / 100), time)) )
Bash
calc_compound_interest(){
: e.g. calc_compound_interest [principle] [rate percentage] [years]
: e.g. calc_compound_interest 100000 10 20
python3 - $@ <<EOF
# -*- coding: utf-8 -*-
import sys
import re
args = sys.argv
def compound_interest(principle, rate, time):
print( principle * (pow((1 + rate / 100), time)) )
compound_interest(${1}, ${2}, ${3})
EOF
}
Python Program for compound interest - GeeksforGeeks
For cases where itโs monthly or quarterly rather than annually, the following equation can be used