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 for simple interest
In this article, we will learn how to calculate simple interest using Python. Simple interest is a method to calculate the interest charge on a loan or deposit.
Simple interest is calculated by multiplying the principal amount by the interest rate and the time period. Unlike compound interest, it doesn't include interest on previously earned interest.
Formula
The mathematical formula for simple interest is:
Simple Interest = (P × T × R) / 100 Where: P = Principal amount (initial money) T = Time period (in years) R = Rate of interest (per annum)
Example Calculation
Let's calculate simple interest with the following values:
P = 1000 (Principal) R = 5 (Rate = 5% per annum) T = 2 (Time = 2 years) Simple Interest = (1000 × 2 × 5) / 100 = 100
Python Implementation
Basic Example
Here's a simple Python program to calculate simple interest ?
# Simple Interest Calculator
principal = 1000
rate = 5
time = 2
# Calculate simple interest
simple_interest = (principal * rate * time) / 100
print(f"Principal Amount: {principal}")
print(f"Rate of Interest: {rate}%")
print(f"Time Period: {time} years")
print(f"Simple Interest: {simple_interest}")
Principal Amount: 1000 Rate of Interest: 5% Time Period: 2 years Simple Interest: 100.0
Interactive Calculator
Let's create a more interactive version that takes user input ?
def calculate_simple_interest(principal, rate, time):
"""Calculate simple interest using the formula (P * R * T) / 100"""
return (principal * rate * time) / 100
# Example with different values
principal = 5000
rate = 7.5
time = 3
simple_interest = calculate_simple_interest(principal, rate, time)
total_amount = principal + simple_interest
print(f"Principal: Rs. {principal}")
print(f"Rate: {rate}% per annum")
print(f"Time: {time} years")
print(f"Simple Interest: Rs. {simple_interest}")
print(f"Total Amount: Rs. {total_amount}")
Principal: Rs. 5000 Rate: 7.5% per annum Time: 3 years Simple Interest: Rs. 1125.0 Total Amount: Rs. 6125.0
Variable Scope Visualization
Key Points
- Simple interest is calculated using the formula: (P × R × T) / 100
- The result represents only the interest amount, not the total
- Total amount = Principal + Simple Interest
- All variables in our examples are declared in global scope
Conclusion
Simple interest calculation in Python is straightforward using basic arithmetic operations. The formula involves multiplication and division to determine the interest earned over a specific time period.
