How to Calculate Compound Interest in Python?
Hi Dev,
This post will give you example of How to Calculate Compound Interest in Python?. We will look at example of Python Program for compound interest. you'll learn Python Program to Calculate Compound Interest. We will look at example of Calculate Compound Interest. So, let's follow few step to create example of Create A Python Program For Compound Interest using Function.
Now let’s see each python program for calculate or compute compound interest; as shown below:
let's see below simple example with output:
Example 1: Python program to compute compound interest
#Python program to compute compound interest
p = float(input("Enter the principal amount : "))
t = float(input("Enter the number of years : "))
r = float(input("Enter the rate of interest : "))
#compute compound interest
ci = p * (pow((1 + r / 100), t))
#print
print("Compound interest : {}".format(ci))
Output:
Enter the principal amount : 1200
Enter the number of years : 2
Enter the rate of interest : 5.4
Compound interest : 1333.0992
Example 2: Python Program to Calculate Compound Interest using Function
#Python program to compute compound interest using function
def compoundInterest(p, r, t):
ci = p * (pow((1 + r / 100), t))
return ci
p = float(input("Enter the principal amount : "))
t = float(input("Enter the number of years : "))
r = float(input("Enter the rate of interest : "))
#call compound interest
ci = compoundInterest(p, r, t)
#print
print("Compound interest : {}".format(ci))
Output:
Enter the principal amount : 1200
Enter the number of years : 2
Enter the rate of interest : 5.4
Compound interest : 1333.0992
- Get Last 2 Digits of Number in Python Tutorial Example
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?