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
- Each
input()asks one question, andfloat()turns each answer into a number. - The interest is 10000 × 7.5 × 3 / 100 = 2250.
:.2fprints money with exactly two decimal places.
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.