Rumah >pembangunan bahagian belakang >Tutorial Python >Tulis program ke kalkulator EMI
Kalkulator EMI:
Kalkulator EMI membantu anda menganggarkan ansuran bulanan anda dengan mudah. Sebaik sahaja anda memasukkan butiran yang diperlukan seperti jumlah pinjaman, tempoh pinjaman dan kadar faedah, kalkulator EMI bank akan memaparkan dengan serta-merta anggaran Ansuran Bulanan Disamakan (EMI) anda.
Untuk mengira EMI anda, anda boleh menggunakan formula berikut:
EMI = [P x R x ( 1 R )^N] / [( 1 R )^N -1]
Di mana :
P = Amaun Prinsipal
R = Kadar Faedah Bulanan (Kadar Faedah Tahunan / 12 bulan)
N = Tempoh Pinjaman dalam bulan
Contoh:
# 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))
Output:
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
Atas ialah kandungan terperinci Tulis program ke kalkulator EMI. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!