# 利用现值关系计算等额本息还款
def adf(r, T):
T = 12 * T #years to mouths
r = r / (100 * 12)
return (1-1/pow(1+r,T)) / r
pv = int(input("请输入贷款金额(万元):"))
r = float(input("请输入利率(%):"))
T = int(input("请输入还款年数:"))
C = pv/adf(r,T) * 10000
print("每月应还:",'%.2f'%C,"元")
结果展示: