编写 EMI 计算器程序
emi 计算器:
emi 计算器可帮助您轻松估算每月分期付款。一旦您输入必要的详细信息,例如贷款金额、贷款期限和利率,银行的 emi 计算器将立即显示您估计的等值每月分期付款 (emi)。
要计算 emi,您可以使用以下公式:
emi = [p x r x ( 1 + r )^n] / [( 1 + r )^n -1]
地点:
p = 本金
r = 月利率(年利率/12个月)
n = 贷款期限(以月为单位)
示例:
# input the loan amountloan = int(input("enter the loan amount: "))# input the loan tenure in years and convert to monthstenure_year = int(input("enter the loan tenure in years: "))tenure_month = tenure_year * 12 # convert years to monthsprint("loan tenure in months:", tenure_month)# input the interest rate per year and convert to monthly interest rateinterest_year = float(input("enter the interest per year: "))interest_month = interest_year / 12 / 100 # convert annual interest rate to monthly decimal rateprint("interest per month in percentage:", interest_month)# calculate emi using the formulaemi = loan * (interest_month * (1 + interest_month) ** tenure_month) / ((1 + interest_month) ** tenure_month - 1)# display the calculated emi, rounded to 2 decimal placesprint("emi:", round(emi, 2))
输出:
Enter the loan amount:500000Enter the loan tenure in years :10Loan tenure in months: 120Enter the interest per year:3.5Interest per month in percentage: 0.002916666666666667EMI: 4944.29