Calculate Simple Interest in Python
Enter 5, not 0.05, for a 5% annual rate in this Python simple-interest exercise. Follow the formula as a beginner and separate earned interest from principal.
1# Program to calculate simple interest23principal = float(input("Enter principal amount: "))4rate = float(input("Enter annual interest rate (in %): "))5time = float(input("Enter time in years: "))67simple_interest = (principal * rate * time) / 10089print("Simple Interest is:", simple_interest)
Sample Output
Simple Interest is: 100.0
1000 × 5 × 2 / 100 earns 100.0 in simple interest.
In this one
- Use annual percentage rates correctly
- Keep time measured in years
- Separate principal from interest earned
How it works
- 1
Read principal, rate, and time as floats.
- 2
Compute their product divided by 100.
- 3
Print simple_interest, not the principal plus interest.
Edge cases
Zero rate
Enter an annual rate of 0.
The product is zero, so no interest is earned.
Months supplied as years
Enter 6 intending six months.
The formula treats it as six years; enter 0.5 for six months.
What's going on
SI = P times R times T divided by 100. R is already a percent. Enter 5 for 5%, not 0.05, or the result is one hundred times too small.
principal is the starting amount, rate is the annual percentage, and time is measured in years. The code multiplies these values and divides by 100 to convert the percentage. For 1000 at 5% over 2 years, the interest is 100.0.
This is simple interest: each year earns interest on the original principal only. There is no power and no interest on earlier interest. The program prints interest, not the final balance. Add principal to simple_interest if you need that balance. For actual financial records, choose explicit rounding rules and a decimal money representation rather than trusting binary floats.
After this program
If the idea is still fuzzy, read Day 1: Introduction to Python in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 25 basic python programs, or see every topic on Python exercises.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What rate input represents 5%?
Pick an answer to check it.
Question 2
Does the result include the principal?
Pick an answer to check it.
Questions people ask
What rate input represents 5%?
Enter 5, because the formula already divides the rate by 100.
Does the result include the principal?
No. simple_interest contains only the earned interest; add principal for the total.
Why is there no exponent?
Simple interest does not compound earlier interest into the balance.