Loan EMI Calculator

Medium ⏱ 12 min 49% acceptance ★★★★☆ 4.2
Write emi(principal, annual_rate_pct, months) using the standard formula P·r·(1+r)^n / ((1+r)^n − 1) where r is the monthly rate. A zero rate means simple division. Round to 2 decimals.

Examples

Example 1
Input
emi(500000, 9, 60)
Output
10379.16
Explanation

5 lakh at 9% over 5 years.

Constraints

  • r = annual_rate_pct / 12 / 100.
  • Handle rate 0 without dividing by zero.

Topics

Business Logicfinance

Companies

HDFC BankBajaj FinservPolicyBazaar

Hints

Hint 1

Compute (1+r)**months once.

Hint 2

Guard the zero-rate branch first.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.