Q:

Write a program to calculate simple interest in Python

0

Write a program to calculate simple interest in Python

In this exercise, we will learn how to calculate Simple Interest using 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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 example, first we created variables as PR, 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 function

In the given 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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python Exercises, Practice Questions and Solutions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a python program to calculate total marks pe... >>
<< Write a Python program to count the occurrences of...