livepython.net

236. Python Program to Calculate a Monthly Loan Payment

EasyPhase 1 · Warm-up

You know input(), float() and the ** sign for powers. That is all you need here.

Overview

When you borrow money from a bank, you often pay it back in equal monthly parts. This monthly part is called the EMI, short for "equated monthly instalment": the same payment every month. Each payment pays back a piece of the loan and the interest on it.

Problem Statement

Mateo wants to borrow money to open a small bakery. Before signing, Mateo wants to know the monthly payment. Banks use this formula:

EMI = P * r * (1 + r) ** n / ((1 + r) ** n - 1)
  • P is the amount borrowed.
  • r is the monthly rate: the yearly rate divided by 12, then divided by 100. A yearly rate of 12 gives r = 0.01.
  • n is the number of months.

Read the amount, the yearly rate and the months. Print Monthly payment: <emi> coins, with the EMI shown with 2 decimal places.

Steps

  1. Read the amount and the yearly rate as decimal numbers, and the months as a whole number.
  2. Work out the monthly rate r: the yearly rate divided by 12, then by 100.
  3. Work out (1 + r) ** n and put it into the formula.
  4. Print the EMI with 2 decimal places.

Examples

Example 1. Input:

12000
12
12

gives:

Monthly payment: 1066.19 coins

Why: r = 12 ÷ 12 ÷ 100 = 0.01. The formula gives 1066.185..., which shows as 1066.19. Mateo pays 12 times, a bit more than 12000 in total, because of the interest.

Example 2. Input:

1000
12
1

gives:

Monthly payment: 1010.00 coins

Why: with only 1 month, Mateo pays everything back at once, plus one month of interest. 1% of 1000 is 10, so the payment is 1000 + 10 = 1010.

Input

Three lines:

  1. The amount borrowed, a number more than 0.
  2. The yearly interest rate in percent, a number more than 0 (it may have a decimal point, like 7.5).
  3. The number of months, a whole number of 1 or more.

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Output

One line: Monthly payment: <emi> coins, with 2 decimal places. The tests try 6 different inputs.

Try it first. The solution opens when you solve this question, or after 3 tries with Submit.

Finish this chapter firstChapter 7 · Getting Input from the User
solution.py
# write your code here

EXPECTED OUTPUT

1Monthly payment: 1066.19 coins

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.