Write a program to calculate simple interest in Python
In this post, we will learn how to calculate Simple Interest using the Python programming language.
Simple interest is a quick and easy method of calculating the interest amount for a particular principal amount of money at some rate of interest. So, simple interest is the simplest and easiest way to determine how much extra you'll have to pay for your loan. For example, when a person takes a loan of Rs. 6000, at a rate of 10 p.a. for three years, the person's interest for three years will be simple interest on the borrowed money.
Simple Interest Formula
The Simple Interest (S.I.) formula is given by-
SI = (P x T x R)/100
Where,
P is the principle amount
T is the time and
R is the rate
Python program to calculate Simple Interest
In the given Python program, first we created variables P, R, and T and then assigned the values to the variables. Then, we calculated the simple interest using the formula Simple_interest = (P * R * T)/100 and printed the output.
P = 1000
T = 5
R = 4
SI = (P * T * R)/100
print('The Simple Interest is', si)
Output of the above code-
The Simple Interest is 200.0
Python program to calculate Simple Interest using user input
The given Python program calculates and prints the simple interest based on principle, rate of interest, and year provided by user at run-time.
print("Enter the principal amount: ")
p = int(input())
print("Enter the rate of interest: ")
r = float(input())
print("Enter the number of years: ")
t = float(input())
si = (p*r*t)/100
print("\nSimple Interest Amount: ")
print(si)
Output of the above code:
Enter the principal amount:
45000
Enter the rate of interest:
8.5
Enter the number of years:
7
Simple Interest Amount:
26775.0
Python program to calculate Simple Interest using function
In the given Python program, we have defined a function cal_simple_interest() to calculate the simple interest. This program allows a user to enter the principal amount, rate of interest, and number of years. By using these values, the program calculates simple interest.
def cal_simple_interest(p,t,r):
# Calculate simple interest
si = (p * t * r)/100
# print output
print('The Simple Interest is : ', si)
return si
# Driver code
p = float(input("Enter the principal amount : "))
t = float(input("Enter the number of years : "))
r = float(input("Enter the rate of interest : "))
cal_simple_interest(p,t,r)
Output of the above code -
Enter the principal amount : 10000
Enter the number of years : 3
Enter the rate of interest : 5
The Simple Interest is : 1500.0
Related Articles
Multiply all elements in list Python
Sum of n numbers in Python using while loop
Find average of n numbers in Python
Python program to multiply two numbers
Reverse pyramid pattern in Python
Fizzbuzz program in Python
Python split string by comma
Python alive progress bar
Python progress bar tqdm
Python language translator code
Python take screenshot of specific window
Web scraping Python BeautifulSoup
Reverse a number in Javascript
HTML open link in new tab
Python print without newline
Python iterate list with index
Python add list to list
Python random choice
Python dict inside list
Remove character from string Python
Python raise keyword