Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - Operators and Expressions

Compute compound interest - Python Program

Example 1 :

p = float(input("Enter principal: ")) r = float(input("Enter rate (%): ")) t = float(input("Enter time (years): ")) amount = p * (1 + r/100) ** t ci = amount - p print("Compound Interest:", round(ci, 2))

Output

 
OUTPUT  :
Enter principal: 1000
Enter rate (%): 5
Enter time (years): 2
Compound Interest: 102.5
 

Example 2 : Using Function

import math def compound_interest(p,r,t): amt = p * (math.pow((1 + (r/100)),t)) print("Compound Amount: ",amt) CI = amt - p return CI p=float(input("Enter Principal Amount: ")) r=float(input("Enter Rate of Interest: ")) t=float(input("Enter Time Period in years: ")) print("Compound interest is",compound_interest(p,r,t))

Output

 
OUTPUT  :
Enter Principal Amount: 100000
Enter Rate of Interest: 12
Enter Time Period in years: 5
Compound Amount: 176234.16832000008
Compound interest is 76234.16832000008