In this post, we will learn how to write a simple interest program in Python by taking input from the user and also we will write this program using the function with a detailed explanation and algorithm.
But before we jump into the algorithm or programming part let’s first discuss the formula of simple interest.
Formula of Simple Interest
Where,
- P = principal amount
- R = Rate of interest
- T = Time period
Algorithm for Simple Interest
- Take input from the user (
p
,r
,t
) - To store the result create a variable called
simple_interest
and do step-3 simple_interest = (p * r * t)/100
- At last print the result (
print(simple_interest)
)
From the above algorithm, we understood how to write a Python program to calculate simple interest. So now let us do it practically.
Few programming concepts you have to know before writing this program:
Source Code
p = int(input("Enter Principal Amount: "))
r = int(input("Enter Rate of Interest: "))
t = int(input("Enter Time Period: "))
simple_interest = (p*r*t)/100
print(f"Simple Interest is: {simple_interest}")
Output
Enter Principal Amount: 50000
Enter Rate of Interest: 10
Enter Time Period: 3
Simple Interest is: 15000.0
Now let us modify the above program and write it using the function.
Simple Interest Program in Python Using Function
Before writing this program Few programming concepts you have to know:
Source Code
def Cal_SI(p,r,t):
return (p*r*t)/100
principal = int(input("Enter Principal Amount: "))
rate = int(input("Enter Rate of Interest: "))
time = int(input("Enter Time Period: "))
print(f"Simple Interest is: {Cal_SI(principal,rate,time)}")
Output
Enter Principal Amount: 250000
Enter Rate of Interest: 7
Enter Time Period: 7
Simple Interest is: 122500.0