Python Program to Find Simple Interest.

This article will discuss the Python Program to calculate Simple Interest. But before understanding Python Code, let us first understand the process of calculating Simple Interest. 


What is Simple Interest?

Simple Interest is the interest calculated on the original amount (also known as the principal) of a loan or deposit, without taking into account any interest earned on the interest. It is calculated as a percentage of the principal and the time period for which the loan or deposit is held.


The formula for calculating simple interest is: Simple Interest = (Principal * Rate * Time) / 100

  • The principal is the original amount of the loan or deposit.
  • Rate is the interest rate, expressed as a percentage.
  • Time is the time period for which the loan or deposit is held, expressed in years.

For example, if you deposit $1000 at an interest rate of 5% for 2 years, the simple interest earned would be $1000 * 5 * 2 / 100 = $100.


Python Programs for Calculating Simple Interest.

Approach 1: Python code using Formula.

# take input for the principal, rate, and time
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the rate of interest: "))
time = float(input("Enter the time period (in years): "))

# calculate the interest using the formula
interest = principal * rate * time / 100

# print the result
print("The interest is", interest)
Output:
Enter the principal amount: 2000
Enter the rate of interest: 5
Enter the time period (in years): 10
The interest is 1000.0


Approach 2: Python Code using a Function.

def simple_interest(principal, rate, time):
    return principal * rate * time / 100

# take input for the principal, rate, and time
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the rate of interest: "))
time = float(input("Enter the time period (in years): "))

# calculate the interest using the function
interest = simple_interest(principal, rate, time)

# print the result
print("The interest is", interest)
Output:
Enter the principal amount: 5000
Enter the rate of interest: 10
Enter the time period (in years): 5
The interest is 2500.0


Approach 3: Python Code using Lambda Function.

# define a lambda function to calculate the simple interest
simple_interest = lambda p, r, t: p * r * t / 100

# take input for the principal, rate, and time
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the rate of interest: "))
time = float(input("Enter the time period (in years): "))

# calculate the interest using the lambda function
interest = simple_interest(principal, rate, time)

# print the result
print("The interest is", interest)
Output:
Enter the principal amount: 25000
Enter the rate of interest: 7
Enter the time period (in years): 5
The interest is 8750.0

⚡ Please share your valuable feedback and suggestion in the comment section below or you can send us an email on our offical email id ✉ algolesson@gmail.com. You can also support our work by buying a cup of coffee ☕ for us.

Similar Posts

No comments:

Post a Comment


CLOSE ADS
CLOSE ADS