PythonMastery

Simple interest program in Python

Read the principal, the yearly rate and the number of years, then calculate simple interest with P × R × T / 100 and the total amount.

Simple interest = principal × rate × time / 100, where the rate is a percentage per year.

The program

python
principal = float(input("Principal: "))
rate = float(input("Rate per year (%): "))
years = float(input("Time (years): "))

interest = principal * rate * years / 100
total = principal + interest

print(f"Simple interest = {interest:.2f}")
print(f"Total amount    = {total:.2f}")

Typed in this example: 10000, 7.5, 3. Press Run to type your own.

output
Principal: 10000
Rate per year (%): 7.5
Time (years): 3
Simple interest = 2250.00
Total amount    = 12250.00

How it works

Banks usually use compound interest, where the interest is added to the principal every period: principal * (1 + rate / 100) ** years. For the same numbers that gives 12422.97.

Related programs: Compound interest.

Learn the idea: Input & Output: Talking to Your User, Operators & Expressions