import math


def compound_interest(P, r, n, t):
    """
    A = the future value of the investment/loan, including interest
    P = the principal investment amount (the initial deposit or loan amount)
    r = the annual interest rate (decimal)
    n = the number of times that interest is compounded per unit t
    t = the time the money is invested or borrowed for
    """
    if(n == "NaN"):
        A = P * math.exp(r*t)
    else:
        A = P * ((1 + r/n)**(n*t))
    return A