我正在学习Python,但我被卡住了。我在找贷款支付金额。我目前有:
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'))
但是,当我跑的时候,我会少跑一点。如果有人能指出我的错误,那就太好了。我使用的是python3.4。在
我想在你最后的计算中
你的括号错了,应该是的
^{pr2}$付款计算方面,您似乎没有正确翻译formula。除此之外,由于内置的
input()
函数返回字符串,因此在将值传递给期望值为数值的函数之前,您需要将它返回的任何内容转换为正确的类型。在我认为正确的公式是
我清理了你的一些变量
^{pr2}$在输入周围添加try-except块也是比较谨慎的。在
相关问题 更多 >
编程相关推荐