def annuity(pval, months, rate):
    """ Calculates how much you have to pay each month if you want to
        pay exactly the same amount each month. The interesting input
        is the amount of $months.

        It does not include the fee so add that later.
    """
    if months == 0:
        return pval
    if round(rate, 0) == 0:
        return pval / months
    p = rate / (100.0 * 12)
    return pval * p / (1 - pow(1 + p, -months))
