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:

  1. Function Definition: Define a function to calculate simple interest.
  2. Input Collection: Collect inputs from the user for principal amount, rate of interest, and time period.
  3. Function Call: Call the function with the collected inputs.
  4. 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}")

 

By Aditya Bhuyan

I work as a cloud specialist. In addition to being an architect and SRE specialist, I work as a cloud engineer and developer. I have assisted my clients in converting their antiquated programmes into contemporary microservices that operate on various cloud computing platforms such as AWS, GCP, Azure, or VMware Tanzu, as well as orchestration systems such as Docker Swarm or Kubernetes. For over twenty years, I have been employed in the IT sector as a Java developer, J2EE architect, scrum master, and instructor. I write about Cloud Native and Cloud often. Bangalore, India is where my family and I call home. I maintain my physical and mental fitness by doing a lot of yoga and meditation.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)