Editor

Compound Interest Calculator

Beginner · Write the code · from Python Numbers: Integers, Floats, and Math You'll Actually Use

From the lesson: Python Numbers: Integers, Floats, and Math You'll Actually Use

You're splitting a restaurant bill with three friends. The total is $85. How much does each person owe? You grab your phone calculator, but a Python programmer just types 85 / 4 and gets the answer instantly.

Read the lesson

Calculate compound interest using this formula:

**A = P * (1 + r) t

Where:

  • P = principal (starting amount) = $1000
  • r = annual interest rate = 0.05 (5%)
  • t = number of years = 10
  • A = final amount
  • Calculate the final amount and the interest earned, then print:

    Final amount: $1628.89
    Interest earned: $628.89

    Round both values to 2 decimal places.

    principal = 1000
    rate = 0.05
    years = 10
    # Calculate the final amount using the formula
    # Calculate interest earned (final - principal)
    # Print the results

    More Numbers exercises

    All Python exercises · 50 practice problems · Python Fundamentals quiz