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.
# 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)
Enter the principal amount: 2000
Enter the rate of interest: 5
Enter the time period (in years): 10
The interest is 1000.0
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)
Enter the principal amount: 5000
Enter the rate of interest: 10
Enter the time period (in years): 5
The interest is 2500.0
# 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)
Enter the principal amount: 25000
Enter the rate of interest: 7
Enter the time period (in years): 5
The interest is 8750.0
No comments:
Post a Comment