Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用此公式计算每月购买付款?_Python_Python 3.x - Fatal编程技术网

Python 如何使用此公式计算每月购买付款?

Python 如何使用此公式计算每月购买付款?,python,python-3.x,Python,Python 3.x,付款=(费率*(1+费率)^N)/((1+费率)^N)-1)) 我被告知“编写一个Python模块(loan.py),为贷款金额、月利率和数字赋值 使用上述公式计算每月付款。” 例如:“如果贷款金额为10000美元,月利率为0.01(或12%年利率),则 付款数量为36,每月付款应为332.14美元。请验证您的程序是否有效 通过使用此数据作为输入,可以正确地执行此操作。” 我尝试过使用下面的代码,但有人告诉我,我正在“将一个浮点除以0” 如果你能告诉我我做错了什么,我将非常感激 interest

付款=(费率*(1+费率)^N)/((1+费率)^N)-1))

我被告知“编写一个Python模块(loan.py),为贷款金额、月利率和数字赋值 使用上述公式计算每月付款。”

例如:“如果贷款金额为10000美元,月利率为0.01(或12%年利率),则 付款数量为36,每月付款应为332.14美元。请验证您的程序是否有效 通过使用此数据作为输入,可以正确地执行此操作。”

我尝试过使用下面的代码,但有人告诉我,我正在“将一个浮点除以0”

如果你能告诉我我做错了什么,我将非常感激

interest_rate=eval(input("What's the loan amount?"))
loan_amount=interest_rate*1.0

interest_rate=eval(input("What's the monthy interest rate?(as a fraction)"))
interest_rate=interest_rate*1.0

number_of_payments=eval(input("What's the number of payments you need to make?")) 
number_of_payments=number_of_payments*1.0

monthly_payment=((interest_rate*(1+interest_rate)**number_of_payments)/(((1+interest_rate)**number_of_payments)-1))

print("Your monthly payment amount would be: ",monthly_payment*loan_amount)
请始终尝试在代码中使用有意义的变量名…这将使您的编程更加轻松

interest_rate=eval(input("What's the loan amount?"))
loan_amount=interest_rate*1.0

interest_rate=eval(input("What's the monthy interest rate?(as a fraction)"))
interest_rate=interest_rate*1.0

number_of_payments=eval(input("What's the number of payments you need to make?")) 
number_of_payments=number_of_payments*1.0

monthly_payment=((interest_rate*(1+interest_rate)**number_of_payments)/(((1+interest_rate)**number_of_payments)-1))

print("Your monthly payment amount would be: ",monthly_payment*loan_amount)