等额本息
#coding=utf-8
import numpy as np
import math
#房贷等额本息算法
#计算房贷等额本息法应还款的额度并输出结果
def averageCapitalPlusInterest(principal,principalRatio,anualInterestRate,month):
#principal表示房价总额,principalRatio表示房贷百分比,anualInterestRate表示房贷年利率,month表示房贷月份
mortgage = np.around(principal*principalRatio,2) #计算需要贷款的金额
monthlyPayment = np.around(mortgage*averageCapitalPlusInterestRate(month,monthlyInterestRate(anualInterestRate)),2) #计算每月应还款金额
totalInt = np.around(totalInterest(mortgage,monthlyPayment,month),2)
mortgageIntoTenThousand = np.around(mortgage/10000,2) #将贷款总金额转化为万元
print("贷款:",mortgageIntoTenThousand,"万元") #输出结果
print("年利率:",anualInterestRate,"%")
print("按揭月数:",month,"月")
print("每月应还:",monthlyPayment,"元") #输出结果
print("需付利息:",totalInt,"元")
totalPayment = np.around(monthlyPayment*month,2) #还款总额
return totalPayment