Simple Interest Calculator
This Python program calculates the simple interest based on the principal amount, rate of interest, and time period. The formula for calculating simple interest is:
Simple Interest = (Principal * Rate * Time) / 100
Program Explanation
The structure of the program is as follows:
- Function Definition: Define a function to calculate simple interest.
- Input Collection: Collect inputs from the user for principal amount, rate of interest, and time period.
- Function Call: Call the function with the collected inputs.
- Output: Display the calculated simple interest.
Python Program
# Function to calculate simple interest
def calculate_simple_interest(principal, rate, time):
"""
Calculate the simple interest.
Args:
principal (float): The principal amount.
rate (float): The rate of interest per year.
time (float): The time period in years.
Returns:
float: The calculated simple interest.
"""
simple_interest = (principal * rate * time) / 100
return simple_interest
# Collecting user input for 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: "))
# Calculating simple interest
interest = calculate_simple_interest(principal, rate, time)
# Displaying the result
print(f"The simple interest is: {interest}")
Explanation of the Program
1. Function Definition
The calculate_simple_interest
function takes three arguments: principal
, rate
, and time
. It calculates the simple interest using the formula and returns the result.
def calculate_simple_interest(principal, rate, time):
simple_interest = (principal * rate * time) / 100
return simple_interest
2. Input Collection
The program collects the principal amount, rate of interest, and time period from the user using the input
function. The inputs are converted to float
to allow for decimal values.
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the rate of interest: "))
time = float(input("Enter the time period in years: "))
3. Function Call
The calculate_simple_interest
function is called with the collected inputs, and the result is stored in the interest
variable.
interest = calculate_simple_interest(principal, rate, time)
4. Output
The calculated simple interest is displayed using the print
function.
print(f"The simple interest is: {interest}")