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
Arguments
[100, 0.05, 12, 6]
Expected return
135
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.