Python3如何在抵押贷款场景中实现资金的时间价值



我想实现一个计算抵押贷款的函数。它接受用户输入,如贷款金额、贷款期限、一年中的付款频率和年化利率。在必要的输入之后,该功能将生成一个输出,向用户显示贷款期限结束后需要支付的总利息和要支付的总金额(总贷款利息+贷款金额(。

这就是我所做的:

def get_mortgage_cashflows():

loan_amount = float(input('Enter mortgage loan amount: '))
loan_period = float(input('Enter the number of period in years: '))
loan_frequency = int(input('Enter the number of payment per year: '))
loan_interest = float(input('Enter the annual interest rate: '))
loan_total_interest = (loan_amount * (1 + (loan_interest / 100) / loan_frequency) ** loan_period) - loan_amount
loan_total_amount = loan_amount + loan_total_interest

return loan_total_interest, loan_total_amount
total_interest, total_amount = get_mortgage_cashflows()
print('total interest: ', total_interest)
print('total payment amount: ', total_amount)

但是,似乎有一个错误,因为没有生成输出。

我课堂活动中的一个示例测试用例:

Mortgage loan: $1,000,000 
Period: 10 years
Frequency: Annual repayment
Annualized interest rate: 1.5%

感谢您的帮助!

使用您的代码,我得到:

Enter mortgage loan amount: >? 1000000
Enter the number of period in years: >? 10
Enter the number of payment per year: >? 1
Enter the annual interest rate: >? 1.5
total interest:  160540.82502514892
total payment amount:  1160540.825025149

你能再次尝试运行你给我们的代码并确认你仍然有问题吗?

最新更新