我想计算抵押的每月还款额

时间:2018-11-17 14:25:17

标签: python

def mortgage_calculator():
    annual_int_rate = 0
    annual_int_rate = float(annual_int_rate)
    mortgage_life = 0
    mortgage_life = float(mortgage_life)
    mortgage_amount = float(raw_input("Enter the amount would you like to borrow: "))

    salary = float(raw_input("Enter your salary per annum: "))

    if salary > 15000 and salary <= 24999 and mortgage_amount > 50000:
        annual_int_rate += 0.15
        mortgage_life += 30
    elif salary > 24999 and salary <= 44999 and mortgage_amount > 50000:
        annual_int_rate += 0.125
        mortgage_life += 25
    elif salary > 45000 and salary <= 64999 and mortgage_amount > 50000:
        annual_int_rate += 0.10
        mortgage_life += 20
    else:
        annual_int_rate += 0.06
        mortgage_life += 15

    r = float(annual_int_rate/12)
    n = mortgage_life * 12
    mnth_paym = mortgage_amount * (r(1 + r)**n/(1 + r)**n - 1)
    print("Monthly payments for the next {} months will be {}".format(n, mnth_paym))

def run():
    employment_check = raw_input("Are you employed [y/n]: ").upper()
    if employment_check == "Y":
        mortgage_calculator()
    else:
        print("You don't qualify for a mortgage")

run()

我想使用抵押贷款计算器方法底部的公式(mnth_paym)计算抵押贷款的月还款额,但出现TypeError。

1 个答案:

答案 0 :(得分:0)

在代码的以下行中,首次使用变量r

后缺少运算符
mnth_paym = mortgage_amount * (r(1 + r)**n/(1 + r)**n - 1)

您是说r * (1 + r) ...吗?