write a program to calculate simple interest python

In this article let's try to learn how to calculate the simple interest of a given  principal amount

Suppose you deposit an amount in the bank you will be given an Yearly or half yearly interest based on the  deposit rates  fixed by the bank.
 
 
 
write a program to calculate simple interest

 
 


In India, Savings Bank deposit rate is  4% and for fixed deposit the interest rate is 7%

Given the principal amount interest rate and time there is a formula to calculate simple interest

SI = (P (1 + rT))

 
Where :

SI is simple interest,
P  is principal amount,
r  is rate of interest fixed by bank and
T  is time in years

Let's assume you have 100 Rupees as a principal amount and you have to deposit for the time of 2 years with the interest rate of 7% let's try to find out simple interest

SI = 100 * (1 + (0.07 * 2))
SI = 100 * (1 + 0.14)
SI = 100 * 1.14
SI = 114

At the end of the two years you will be getting principal amount 100 plus simple interest 15 that is 115


let's write a Python program to ask user to enter principal amount rate of interest and time in years  and try to find out the simple interest


principal = float(input("Enter Principal Amount : "))
rate = float(input("Enter Rate of Interest : "))
time = int(input("Enter Time of Deposit in Years : "))

simple_interest = principal * (1 + (rate * time))

print("Simple Interest is : %.2f " %simple_interest)



OUTPUT 1:

Enter Principal Amount : 100
Enter Rate of Interest : 0.07
Enter Time of Deposit in Years : 2
Simple Interest is : 114.00


OUTPUT 2:

Enter Principal Amount : 500
Enter Rate of Interest : 0.10
Enter Time of Deposit in Years : 1
Simple Interest is : 550.00 



Sometimes their interest rate will be multiplied by hundred so in that case you have to get the interest rate in fraction. Just divide the interest rate by 100 you will get the fraction


principal = float(input("Enter Principal Amount : "))
rate = float(input("Enter Rate of Interest (In Percentage): ")) / 100
time = int(input("Enter Time of Deposit in Years : "))

simple_interest = principal * ( 1 + (rate * time))

print("Simple Interest is : %.2f " %simple_interest)


 
 
OUTPUT : 
 
Enter Principal Amount : 100
Enter Rate of Interest (In Percentage): 7
Enter Time of Deposit in Years : 2
Simple Interest is : 114.00 



The program can also be written as below

principal = float(input("Enter Principal Amount : "))
rate = float(input("Enter Rate of Interest (In Percentage): "))
time = int(input("Enter Time of Deposit in Years : "))

rate = rate / 100
simple_interest = principal * ( 1 + (rate * time))

print("Simple Interest is : %.2f " %simple_interest)


 
OUTPUT:

Enter Principal Amount : 100
Enter Rate of Interest (In Percentage): 4
Enter Time of Deposit in Years : 5
Simple Interest is : 120.00 



Conclusion: Try to Running  the program by yourself and  change the principal amount, interest rate and time of deposit  with  any Random numbers, try to calculate the simple interest.

Post a Comment

0 Comments