Let's check the mathematical formulas of simple and compound interest.
Simple Interest = (principal * time * rate) / 100
Compound Interest = principal((1 + rate / 100)time - 1)
We will calculate the simple interest using Python code here. We will use "*" and "/" arithmetic operators of Python to calculate that. We will be using the above Simple Interest formula for the calculation. Let's check the Python program to understand it.
# input values required
principal_amount = 10000
time = 4
rate_of_interest = 14
# calculate the simple interest
simple_interest = (principal_amount * time * rate_of_interest)/100
print("Simple interest is: ", simple_interest)
Output
Simple interest is: 5600.0
In the above Python code example
The compound interest can be calculated in Python using two methods. The first is that we use "*", "/" and "**" operators and the second is using "*", "/" and pow() function. We will be using the mathematical formula of Compound Interest to calculate it in Python.
# Example 1
# input values required
principal_amount = 10000
time = 4
rate_of_interest = 14
# calculate the simple interest
compound_interest = principal_amount * ((1 + rate_of_interest / 100)**time - 1)
print("Compound interest is: ", compound_interest)
Output
Compound interest is: 6889.601600000008
# Example 2: Using pow() function
# input values required
principal_amount = 8000
time = 4
rate_of_interest = 13.25
# calculate the compound interest
amount = principal_amount * (pow((1 + rate_of_interest / 100), time))
compound_interest = amount - principal_amount
print("Compound interest is: ", compound_interest)
Output
Compound interest is: 5159.604275312504
0 Comments