Maintenance

Site is under maintenance — quizzes are still available.

Go to quizzes
Sponsored Reserved space — layout preview until AdSense is connected
easy +12 pts

Compound interest

Future value with periodic compounding.

Implement `compound_interest( principal: float, annual_rate: float, years: int, compounds_per_year: int = 12, ) -> float`. Use the standard formula: `A = P × (1 + r/n)^(n×t)` Where `P` is principal, `r` is the annual rate (e.g. `0.05` for 5%), `n` is compounds per year, and `t` is years. Return the balance rounded to **two decimal places** with `round(..., 2)`.

Constraints

principal ≥ 0; 0 ≤ annual_rate ≤ 1; years ≥ 0; compounds_per_year ≥ 1

Example

>>> compound_interest(1000, 0.05, 1, 12)
1051.16
>>> compound_interest(2000, 0.06, 2, 1)
2247.2
12 points ~12 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use `(1 + annual_rate / compounds_per_year) ** (compounds_per_year * years)`.
Wrap the final amount in `round(..., 2)` before returning.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.
Sponsored Reserved space — layout preview until AdSense is connected