抵押计算器数学

2024-04-27 05:42:43 发布

您现在位置:Python中文网/ 问答频道 /正文

这个程序运行得很好,但它返回的每月付款是完全不可用的。如果本金为400000美元,利率为11%,付款期为10年,则每月返回44000.16美元。我在谷歌上搜索了方程(算法?)我不知道我哪里出错了。在

import locale
locale.setlocale(locale.LC_ALL, '')

def mortgage(principal, interest, n):
    payment = principal*((interest*(1+interest)**n) / ((1+interest)**n-1))
    return payment

principal = float(input("What is the amount of the loan you are taking out? $"))
interest = float(input("What is the interest rate? (%) ")) / 100
n = float(input("How many years? ")) * 12
print
print "Your monthly payment would be", locale.currency(mortgage(principal, interest, n))

Tags: the程序运行principalinputispaymentfloatwhat
1条回答
网友
1楼 · 发布于 2024-04-27 05:42:43

问题在于你使用的利率。你要求的是年利率,而不是月利率。在

来自https://en.wikipedia.org/wiki/Mortgage_calculator#Monthly_payment_formula

r - the monthly interest rate, expressed as a decimal, not a percentage. Since the quoted yearly percentage rate is not a compounded rate, the monthly percentage rate is simply the yearly percentage rate divided by 12; dividing the monthly percentage rate by 100 gives r, the monthly rate expressed as a decimal.

我刚在我的电脑上试过,把利率除以12,计算出5510美元/月,这与其他抵押贷款计算器是一致的。在

相关问题 更多 >