Write a Program to Calculate Simple Interest in Python

Write a Program to Calculate Simple Interest in Python

The objective of this Python post, you will see various Python examples that cover the following:

  • Write a Program to Calculate Simple Interest in Python
  • Simple Interest Program in Python using Function

Let us have a look at the formula for calculating the simple interest.

(P * N * R)/100

Where,
P is the principal amount
R is the rate and
N is the time span

Now let’s see each one by one:

1: Write a Program to Calculate Simple Interest in Python

  • Use a python input() function in your python program that takes an input from the user.
  • Next, calculate the simple interest using this SI = (P * N * R)/100  formula.
  • After the end program, print the simple interest.
#Python program to calculate simple interest

P = float(input("Enter the principal amount : "))

N = float(input("Enter the number of years : "))

R = float(input("Enter the rate of interest : "))

#calculate simple interest by using this formula
SI = (P * N * R)/100

#print
print("Simple interest : {}".format(SI))

Output

Enter the principal amount :  1000 
Enter the number of years :  2 
Enter the rate of interest :  5 
Simple interest : 100.0 

2: Simple Interest Program in Python using Function

  • Define a function in your python program that accepts the argument and calculate simple interest by using this SI = (P * N * R)/100 formula.
  • Use a python input() function in your python program that takes an input from the user.
  • Next, call a simple interest function with specific arguments.
  • After the end program, print the simple interest.
#Python program to calculate simple interest using function

def simpleInterest(P, N, R):
    SI = (P * N * R)/100
    return SI
  
 
P = float(input("Enter the principal amount : "))

N = float(input("Enter the number of years : "))

R = float(input("Enter the rate of interest : "))

#calculate simple interest by using this formula
SI = simpleInterest(P, N, R)

#print
print("Simple interest : {}".format(SI))

Output

Enter the principal amount :  1000 
Enter the number of years :  2 
Enter the rate of interest :  5 
Simple interest : 100.0 

Leave a Reply

Your email address will not be published. Required fields are marked *