In this Tutorial -:

Understanding the Problem
In financial calculations, simple interest is a basic formula used to calculate the interest earned on a principal amount over a specific period. The formula for simple interest is:
Simple Interest (SI) = (Principal Amount * Rate of Interest * Time) / 100
In this tutorial, we’ll develop a Python program to calculate simple interest by taking user input for principal amount, rate of interest, and time period.
Developing the Algorithm
-> Take user input for the principal amount, rate of interest, and time period.
-> Calculate the simple interest using the provided formula.
-> Display the calculated simple interest to the user.
Writing the Python Code
# Function to calculate compound interest
def calculate_compound_interest(principal, rate, time, frequency):
amount = principal * (1 + (rate / (100 * frequency))) ** (frequency * time)
compound_interest = amount - principal
return compound_interest
# Main function
def main():
# Input principal amount, rate of interest, time period, and compounding frequency
principal_amount = float(input("Enter the principal amount: "))
rate_of_interest = float(input("Enter the rate of interest: "))
time_period = float(input("Enter the time period (in years): "))
compounding_frequency = int(input("Enter the compounding frequency per year: "))
# Calculate compound interest
compound_interest = calculate_compound_interest(principal_amount, rate_of_interest, time_period, compounding_frequency)
# Display the result
print("Compound Interest:", round(compound_interest, 2))
if __name__ == "__main__":
main()
O/P
Enter the principal amount: 5000
Enter the rate of interest: 5.5
Enter the time period (in years): 2
Simple Interest: 579.9
Time Complexity
The time complexity of this program is constant (O(1)) because the execution time does not depend on the size of the input. It will always execute a fixed number of operations regardless of the input values.
Code Explanation
We define a function calculate_simple_interest that takes three arguments: principal amount, rate of interest, and time period. Inside the function, we calculate the simple interest using the provided formula and return the result.
The main function is defined to take user input for principal amount, rate of interest, and time period.
User inputs are converted to floating-point numbers using float(input(…)).
The calculate_simple_interest function is called with the user-provided inputs, and the result is stored in the simple_interest variable.
Finally, the calculated simple interest is displayed to the user.
Dry Run
Let’s perform a dry run of the program with the following inputs:
Principal amount = 5000
Rate of interest = 5.5
Time period = 2
Execution:
User enters the principal amount: 5000
User enters the rate of interest: 5.5
User enters the time period (in years): 2
The calculate_simple_interest function is called with principal_amount = 5000, rate_of_interest = 5.5, and time_period = 2.
The simple interest is calculated as follows:
simple_interest = (5000 * 5.5 * 2) / 100 = 550
The calculated simple interest (550) is displayed to the user.
The program successfully calculates and displays the simple interest based on the user inputs.
