← Programming questions
Easy / PYTHON

Compound Interest

python_basics · arithmetic · finance 8 minute study target

Not completed

Challenge

Implement compound_interest(P, r, n, t). The principal P is non-negative, the annual rate r is a non-negative decimal, n is a positive integer (compounding periods per year), and t is a non-negative integer number of years. Return round(P * (1 + r / n) ** (n * t)) as an integer, using Python's rounding convention. There are no deposits, withdrawals, fees, or taxes. Avoid rounding intermediate values.

Target complexity: O(1) arithmetic operations

Return values are checked by type. Use the exact function name. Print output is not your answer. Tests have time and memory limits.

Public examples

Example 1

Arguments

[100, 0.05, 12, 6]

Expected return

135
Example 2

Arguments

[5000, 0.1, 12, 40]

Expected return

268503
Hint

Match the return value and type to the contract.

The worked solution unlocks after completion, or with Premium access.

compound_interest.pyPython 3.12

Drafts are saved to your account, not to shared browser storage.

Sign in to submit code and save progress.

Results

Your results will appear here.

Hidden tests reveal only their pass/fail status, never their inputs or expected outputs. Runtime is observed wall time—not an inferred complexity class.

© 2026 EverythingQuant. All Rights Reserved.