贷款支付计算 [英] Loan payment calculation

查看:127
本文介绍了贷款支付计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Python并被卡住.我正在尝试查找贷款还款额.我目前有:

I am learning Python and am stuck. I am trying to find the loan payment amount. I currently have:

def myMonthlyPayment(Principal, annual_r, n):
    years = n
    r = ( annual_r / 100 ) / 12
    MonthlyPayment = (Principal * (r * ( 1 + r ) ** years / (( 1 + r ) ** (years - 1))))
    return MonthlyPayment

n=(input('Please enter number of years of loan'))
annual_r=(input('Please enter the interest rate'))
Principal=(input('Please enter the amount of loan'))

但是,当我跑步时,我会离开很少的地方.如果有人可以指出我的错误,那就太好了.我正在使用Python 3.4.

However, when I run, I am off by small amount. If anyone can point to my error, it would be great. I am using Python 3.4.

推荐答案

付款计算方面,您似乎没有翻译

Payment calculation-wise, you don't appear to have translated the formula correctly. Besides that, since the built-in input() function returns strings, you'll need to convert whatever it returns to the proper type before passing the values on to the function which expects them to numeric values.

def myMonthlyPayment(Principal, annual_r, years):
    n = years * 12  # number of monthly payments
    r = (annual_r / 100) / 12  # decimal monthly interest rate from APR
    MonthlyPayment = (r * Principal * ((1+r) ** n)) / (((1+r) ** n) - 1)
    return MonthlyPayment

years = int(input('Please enter number of years of loan: '))
annual_r = float(input('Please enter the annual interest rate: '))
Principal = int(input('Please enter the amount of loan: '))

print('Monthly payment: {}'.format(myMonthlyPayment(Principal, annual_r, years)))

这篇关于贷款支付计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆