首页 > 后端开发 > Python教程 > 编写 EMI 计算器程序

编写 EMI 计算器程序

Barbara Streisand
发布: 2024-11-23 13:25:16
原创
503 人浏览过

Write a program to EMI calculator

EMI 计算器:

EMI 计算器可帮助您轻松估算每月分期付款。一旦您输入必要的详细信息,例如贷款金额、贷款期限和利率,银行的 EMI 计算器将立即显示您估计的等值每月分期付款 (EMI)。

要计算 EMI,您可以使用以下公式:

EMI = [P x R x ( 1 R )^N] / [( 1 R )^N -1]

地点:

P = 本金

R = 月利率(年利率/12个月)

N = 贷款期限(以月为单位)

示例:

# Input the loan amount
loan = int(input("Enter the loan amount: "))

# Input the loan tenure in years and convert to months
tenure_year = int(input("Enter the loan tenure in years: "))
tenure_month = tenure_year * 12  # Convert years to months
print("Loan tenure in months:", tenure_month)

# Input the interest rate per year and convert to monthly interest rate
interest_year = float(input("Enter the interest per year: "))
interest_month = interest_year / 12 / 100  # Convert annual interest rate to monthly decimal rate
print("Interest per month in percentage:", interest_month)

# Calculate EMI using the formula
emi = loan * (interest_month * (1 + interest_month) ** tenure_month) / ((1 + interest_month) ** tenure_month - 1)

# Display the calculated EMI, rounded to 2 decimal places
print("EMI:", round(emi, 2))
登录后复制

输出:

Enter the loan amount:500000
Enter the loan tenure in years :10
Loan tenure in months: 120
Enter the interest per year:3.5
Interest per month in percentage: 0.002916666666666667
EMI: 4944.29


登录后复制

以上是编写 EMI 计算器程序的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:dev.to
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板