Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Python Program to Compute Simple Interest Given all the Required Values
When it is required to compute simple interest when the principal amount, rate, and time are given, we can use the standard formula: Simple Interest = (Principal × Time × Rate) / 100.
Below is a demonstration of the same ?
Simple Interest Formula
The mathematical formula for calculating simple interest is:
Simple Interest = (Principal × Time × Rate) / 100
Where:
- Principal ? The initial amount of money
- Time ? Duration in years
- Rate ? Annual interest rate (percentage)
Example
# Taking user inputs for simple interest calculation
principal_amt = float(input("Enter the principal amount: "))
time_years = int(input("Enter the time in years: "))
interest_rate = float(input("Enter the interest rate (%): "))
# Calculate simple interest using the formula
simple_interest = (principal_amt * time_years * interest_rate) / 100
# Display the result
print("The computed simple interest is:")
print(simple_interest)
Output
Enter the principal amount: 45000 Enter the time in years: 3 Enter the interest rate (%): 6 The computed simple interest is: 8100.0
Using a Function
We can also create a reusable function to calculate simple interest ?
def calculate_simple_interest(principal, time, rate):
"""Calculate simple interest using the standard formula"""
return (principal * time * rate) / 100
# Example usage
principal = 45000
time = 3
rate = 6
result = calculate_simple_interest(principal, time, rate)
print(f"Principal: ${principal}")
print(f"Time: {time} years")
print(f"Rate: {rate}%")
print(f"Simple Interest: ${result}")
Principal: $45000 Time: 3 years Rate: 6% Simple Interest: $8100.0
How It Works
The principal amount, interest rate, and time period are taken as user inputs using
input()The simple interest formula is applied:
(principal × time × rate) / 100The calculated value is stored in a variable and displayed on the console
The function approach makes the code reusable for different calculations
Conclusion
Simple interest calculation is straightforward using the formula (P×T×R)/100. You can implement it with direct calculation or create a reusable function for multiple calculations.
