Skip to main content
  • Python is available now. All other compilers are coming soon.

    Python
  • Popular Tutorials

    • Getting Started With Python
    • Python if Statement
    • while Loop in Python
    • Python Lists
    • Dictionaries in Python
    All Python Tutorials

    Reference Materials

    Built-in FunctionsList MethodsDictionary MethodsString Methods
    View all

Online Compilers

  • Python Compiler
  • Python Playground
  • Python Projects
  • Exercises

Tutorials

  • Learn Python
  • Python for Beginners
  • Variables and Types
  • Python Strings
  • Python Lists
  • Python If Else
  • Python For Loops
  • Python Functions
  • Python Classes

Examples

  • Python Examples
  • Hello World
  • Add Two Numbers
  • Even or Odd
  • Factorial
  • Fibonacci
  • Prime Check
  • Palindrome Check

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Use
  • Disclaimer

© 2026 ILoveCompiler. All rights reserved.

  1. Home
  2. Python Examples
  3. Calculate Simple Interest

Operators · Python example

Calculate Simple Interest

Use arithmetic operators and formatted floats to compute interest.

Open the compilerAll examples
beginnerarithmeticfloat formattingfinance

Simple interest is calculated with a short formula. This example also shows how to round floating-point output to two decimal places.

example.py
principal = 1500
rate = 7.5
years = 3

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

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

How the code works

  • Python multiplies principal, rate, and years, then divides by 100.
  • The interest is added to the principal to get the total amount.
  • Both values are formatted as currency-like decimals for display.

Key ideas

  • The formula is principal × rate × time ÷ 100 when the rate is a percentage.
  • .2f inside an f-string formats a float with two digits after the decimal point.
  • Parentheses make the order of operations explicit.

Try changing it

  • Read principal, rate, and years with input().
  • Compare simple interest with compound interest.
  • Format the values with a currency symbol.

Related examples

beginner

Add Two Numbers

Store two integers in variables and print their sum with an f-string.

intermediate

Quadratic Equation Roots

Use the quadratic formula and math.sqrt to find real roots.

Previous exampleVariables and Data TypesNext exampleArea and Circumference of a Circle

Expected output

Simple interest: 337.50
Total amount: 1837.50

Output is compared after trimming trailing whitespace on each line. Run the code to see it produced by CPython in your browser.

Practice next

Apply the same idea with automatic tests or browse a guided project.

ExercisesProjects