How to calculate simple interest in Python

This Python tutorial explains how to calculate simple interest in Python. Apart from the Python program to calculate simple interest, we will cover the below topics:

  • Python program to calculate simple interest from user input
  • Python Program for simple interest
  • Python Program to compute simple interest
  • Python program to calculate simple interest using function
  • Python program for simple interest and compound interest

Python Program for simple interest

Let’s see python program for simple interest.

  • Firstly, we will create a variable as P, R, and T and assign the value to the variable.
  • We will calculate the simple interest using the formula Simple_interest = (P * R * T) / 100.
  • At last, print the Simple_interest to get the output.

Example:

P = 300
R = 1
T = 4
Simple_interest = (P * R * T) / 100
print("The simple interest is:", Simple_interest)

You can refer to the below screenshot to see the output for python program for simple interest.

Python Program for simple interest
Python Program for simple interest

This code we can use to calculate simple interest in Python.

Read Python creates a dictionary from two lists

Python program to calculate simple interest from user input

Let see program to calculate simple interest from user input.

  • In this example, we will use the input() function to take input from the user for the principal amount, time, and rate.
  • To compute simple interest we will use the formula simple_interest=(principle*time*rate)/100.
  • And at last print simple_interest to get the output.

Example:

principal = float(input('Enter the principle amount: '))
time = float(input('Enter the time: '))
rate = float(input('Enter the rate: '))
simple_interest = (principal*time*rate)/100
print("Simple interest is:", simple_interest)

You can refer to the below screenshot to see the output for the python program to calculate simple interest from user input.

Python program to calculate simple interest from user input
Python program to calculate simple interest from user input

The above Python code we can use to calculate simple interest from user input.

Read Python loop through a list

Python Program to compute simple interest

Now, we will see a python program to compute simple interest.

  • In this example, we will use the input() function to take input from the user for the principal amount, time, and rate.
  • To compute simple interest we will use the formula Simple_interest=(principle*time*rate)/100.
  • And at last print Simple_interest to get the output.

Example:

principle=float(input("Enter the principle amount:"))
time=int(input("Enter the time(years):"))
rate=float(input("Enter the rate:"))
Simple_interest=(principle*time*rate)/100
print("The simple interest is:",Simple_interest)

You can refer to the below screenshot to see the output for the python program to compute simple interest.

Python Program to compute simple interest
Python Program to compute simple interest

Read Matplotlib plot bar chart

Python program to calculate simple interest using function

Here, we will see python program to calculate simple interest using function.

  • Firstly, we will define a function as def Simple_interest(P, R, T)
  • We will use the simple interest formula Si = (P * R * T)/100 where P is the principle amount, R is the rate, and T is the time.
  • Now, call the Simple_interest function with specific arguments.
  • And at last print Si to get the output.

Example:

def Simple_interest(P,R,T):
    print('The principal is', P)
    print('The rate of interest is', R)
    print('The time period is',T)
    Si = (P * R * T)/100
    print('The Simple Interest is', Si)
    return Si
Simple_interest(12, 8, 6)

You can refer to the below screenshot to see the output for the python program to calculate simple interest using function.

Python program to calculate simple interest using function
Python program to calculate simple interest using function

The above Python code we can use to calculate simple interest using a function in Python.

Read For loop vs while loop in Python

Python program for simple interest and compound interest

Here, we will see python program for simple interest and compound interest.

  • In this example, we will use the input() function to take input from the user for the principal amount, rate, and time.
  • We will calculate Simple_interest and Compound_interest.
  • The formula used is Simple_interest = (principal*rate*time)/100 and Compound_interest = principal * ((1+rate/100)**time – 1).
  • To display the result we will print Simple_interest and Compound_interest.

Example:

principal = float(input('Enter principal amount: '))
rate = float(input('Enter rate of interest: '))
time = float(input('Enter time in number of years: '))
Simple_interest = (principal*rate*time)/100
Compound_interest = principal * ((1+rate/100)**time - 1)
print("Simple interest is:", Simple_interest)
print("Compound interest is:", Compound_interest)

You can refer to the below screenshot to see the output for the python program for simple interest and compound interest.

Python program for simple interest and compound interest
Python program for simple interest and compound interest

This is the python program for simple interest and compound interest.

You may like the following Python tutorials:

In this Python tutorial, we have learned about the Python program to calculate simple interest. Also, we covered these below topics:

  • Python program to calculate simple interest from user input
  • Python Program for simple interest
  • Python Program to compute simple interest
  • Python program to calculate simple interest using function
  • Python program for simple interest and compound interest