Write a Python program to Calculate Simple Interest with an example. Before we get into the example, let me show you the formula behind the Simple Interest calculation:
SI = (Principal Amount * Rate of Interest * Number of years) / 100
Python Program to calculate simple interest
This Python program allows users to enter the Principal Amount, ROI, and Number of years. By using those values, the program calculates Simple Interest using the above-specified formula. For more examples, refer to the Python Basic Programs.
princ_amount = float(input(" Please Enter the Principal Amount : "))
rate_of_int = float(input(" Please Enter the Rate Of Interest : "))
time_period = float(input(" Please Enter Time period in Years : "))
simple_interest = (princ_amount * rate_of_int * time_period) / 100
print("\nSimple Interest for Principal Amount {0} = {1}".format(princ_amount, simple_interest))

Simple Interest Program using functions
In the following program, we define a function that accepts the principal amount, interest rate, and time period as arguments. Next, it uses the mathematical formula to calculate the simple interest.
def calSimpleInt(p, r, t):
return (p * r * t) / 100
amt = float(input("Enter the Principal Amount = "))
ir = float(input("Enter the Interest Rate = "))
tpy = float(input("Enter Time Period in Years = "))
si = calSimpleInt(amt, ir, tpy)
print('The Simple Interest = ', si)
Enter the Principal Amount = 10000
Enter the Interest Rate = 7.5
Enter Time Period in Years = 5
The Simple Interest = 3750.0
Calculate simple interest using the lambda function
In the program below, the lambda expression creates an anonymous function to calculate the simple interest. Refer to Python lambda.
si = lambda p, t, r: (p * r * t) / 100
p = 150000
r = 3.5
t = 7
si = si(p, t, r)
print('The Simple Interest = ', si)
The Simple Interest = 36750.0
Find simple interest in Python using list comprehension
In the following example, we declare a list of tuples where each tuple contains the principal amount, interest rate, and time period. Here, we use list comprehension to calculate the simple interest of multiple items in a list of tuples. Refer to Python list comprehensions.
data = [(10000, 4.5, 3), (10000, 5, 6), (10000, 7, 12)]
si = [(p * r * t) / 100 for p, r, t in data]
print('The Simple Interest = ', si)
The Simple Interest = [1350.0, 3000.0, 8400.0]
Also Read