Write a Python program that calculates simple interest based on the principal amount, interest rate, and time period provided.
Simple Interest is a basic financial concept used to calculate the interest earned or paid on a principal amount over a certain period of time, based on a fixed interest rate.his is a Python Program to compute simple interest given all the required values.
Some common terms in the calculation of Simple interest:
- Principal: The initial amount of money borrowed or invested.
- Interest Rate: The percentage applied to the principal to calculate the interest.
- Time Period: The duration for which the money is borrowed or invested, typically measured in years.
1. Take in the values for principle amount, rate and time.
2. Using the formula, compute the simple interest.
3. Print the value for the computed interest.
4. Exit.
Simple Interest = (P × R × T)/100
Here, P = Principal Amount, R = Rate of Interest and T = Time.
Find the Simple Interest on Rs. 200 for 5 years at 5% per annum compounded annually.
Solution:
Given, P = 200, R = 5 and T = 5.
Simple Interest (SI) = (P * R * T)/100
SI = (200 * 5 * 5)/100
SI = 5000/100
SI = 50
Hence, the Simple Interest on Rs.200 at the rate of 5% for 5 years is Rs. 50
Here is source code of the Python Program to compute simple interest given all the required values. The program output is also shown below.
principle=float(input("Enter the principle amount:")) time=int(input("Enter the time(years):")) rate=float(input("Enter the rate:")) simple_interest=(principle*time*rate)/100 print("The simple interest is:",simple_interest)
1. User must enter the values for the principle amount, rate and time.
2. Calculate the simple interest using the formula: (principal*time*rate)/100
3. Print the calculated simple interest.
Time Complexity: O(1)
The time complexity of the given program is O(1) because the execution time is constant and does not depend on the input size.
Space Complexity: O(1)
The space complexity of the program is O(1) as well because the amount of memory used by the program remains constant regardless of the input size.
Testcase 1: In this case, enter P=200, R=5, and T=5 as the parameters to calculate simple interest.
Enter the principle amount:200 Enter the time(years):5 Enter the rate:5.0 The simple interest is: 50.0
Testcase 2: In this case, enter P=70000, R=4, and T=1 as the parameters to calculate simple interest.
Enter the principle amount:70000 Enter the time(years):1 Enter the rate:4.0 The simple interest is: 2800.0
To practice programs on every topic in Python, please visit “Programming Examples in Python”.
- Check Python Books
- Apply for Programming Internship
- Check Information Technology Books
- Practice Programming MCQs
- Apply for Python Internship