Drill

ProblemsPython › finance

Balance after yearly compounding

easyfinancePython

An account reinvests its interest once a year. Report the balance after a whole number of years.

compound_balance(principal: int, rate_percent: int, years: int) → int

Solve it in the editor →

Where you start

def compound_balance(principal: int, rate_percent: int, years: int) -> int:
    

Worked examples

CallResult
compound_balance(1000, 10, 2)1210
compound_balance(100, 5, 3)115
compound_balance(5000, 0, 5)5000
compound_balance(0, 10, 5)0

Hint

Loop the years, adding the floored interest each pass.

Reference solution in Python
def compound_balance(principal: int, rate_percent: int, years: int) -> int:
    balance = principal
    for _ in range(years):
        balance += balance * rate_percent // 100
    return balance

The same problem in another language

More finance problems in Python