The description is rather long but it tries to explain what a financing plan is. 

The fixed monthly payment for a fixed rate mortgage is the amount paid by the borrower every month that ensures 
that the loan is paid off in full with interest at the end of its term. 

The monthly payment formula is based on the annuity formula. 
The monthly payment `c` depends upon:

- `rate` - the monthly interest rate is expressed as a decimal, not a percentage. 
The monthly rate is simply the **given** yearly percentage rate divided by 100 and then by 12.

- `term` - the number of monthly payments, called the loan's `term`.
- `principal` - the amount borrowed, known as the loan's principal (or `balance`).

First we have to determine `c`.

We have: `c = n /d` with `n = r * balance` and `d = 1 - (1 + r)**(-term)` where `**` is the `power` function (you can look at the reference below).

The payment `c` is composed of two parts. The first part pays the interest (let us call it `int`)
due for the balance of the given month, the second part repays the balance (let us call this part `princ`) hence for the following month we get a `new balance = old balance - princ` with `c = int + princ`. 

Loans are structured so that the amount of principal returned to the borrower starts out small and increases with each mortgage payment. 
While the mortgage payments in the first years consist primarily of interest payments, the payments in the final years consist primarily of principal repayment.

A mortgage's amortization schedule provides a detailed look at precisely what portion of each mortgage payment is dedicated to each component.

In an example of a $100,000, 30-year mortgage with a rate of 6 percents the amortization schedule consists of 360 monthly payments.
The partial amortization schedule below shows with 2 decimal floats
the balance between principal and interest payments.

--|num_payment|c          |princ      |int        |Balance    |
--|-----------|-----------|-----------|-----------|-----------|
--|1          |599.55     |99.55      |500.00     |99900.45   |
--|...        |599.55     |...        |...        |...        |
--|12         |599.55     |105.16     |494.39     |98,771.99  |
--|...        |599.55     |...        |...        |...        |
--|360        |599.55     |596.57     |2.98       |0.00       |

# Task:
Given parameters 
```
rate: annual rate as percent (don't forgent to divide by 100*12)
bal: original balance (borrowed amount) 
term: number of monthly payments
num_payment: rank of considered month (from 1 to term)
```
the function `amort` will return a formatted string:

`"num_payment %d c %.0f princ %.0f int %.0f balance %.0f" (with arguments num_payment, c, princ, int, balance`)

# Examples:
```
amort(6, 100000, 360, 1) ->
"num_payment 1 c 600 princ 100 int 500 balance 99900"

amort(6, 100000, 360, 12) ->
"num_payment 12 c 600 princ 105 int 494 balance 98772"

```
# Ref

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def amort(rate, bal, term, num_payments):
	

Solutions:
def amort(rate, bal, term, num_payments):
	monthlyRate = rate / (12 * 100)
	c = bal * (monthlyRate * (1 + monthlyRate) ** term) / ((1 + monthlyRate) ** term - 1)
	newBalance = bal
	for i in range(num_payments):
		interest = newBalance * monthlyRate
		princ = c - interest
		newBalance = newBalance - princ
	return 'num_payment %s c %.0f princ %.0f int %.0f balance %.0f' % (num_payments, c, princ, interest, newBalance)


def amort(rate, bal, term, num_payments):
	r = rate / (100 * 12)
	n = r * bal
	d = 1 - (1 + r) ** (-term)
	c = n / d
	for i in range(num_payments):
		int_ = r * bal
		princ = c - int_
		bal -= princ
	return 'num_payment %d c %.0f princ %.0f int %.0f balance %.0f' % (num_payments, c, princ, int_, bal)


def calc_balance(r, n, bal, c):
	return (1 + r) ** n * bal - ((1 + r) ** n - 1) / r * c

def amort(rate, bal, term, num_payment):
	r = rate / 100 / 12
	n = r * bal
	d = 1 - (1 + r) ** (-term)
	c = n / d
	new_balance = calc_balance(r, num_payment, bal, c)
	old_balance = calc_balance(r, num_payment - 1, bal, c)
	princ = old_balance - new_balance
	intr = c - princ
	return 'num_payment {} c {:.0f} princ {:.0f} int {:.0f} balance {:.0f}'.format(num_payment, c, princ, intr, new_balance)


def amort(rate, bal, term, num_payments):
	r = rate / 1200
	c = bal * (r / (1 - (1 + r) ** (-term)))
	b = bal * (1 + r) ** (num_payments - 1) - c * (((1 + r) ** (num_payments - 1) - 1) / r)
	i = r * b
	a = c - i
	b -= a
	return 'num_payment {} c {:.0f} princ {:.0f} int {:.0f} balance {:.0f}'.format(num_payments, c, a, i, b)


def amort(rate, bal, term, num_payments):
	r = rate / (100 * 12)
	c = r * bal / (1 - pow(1 + r, -term))
	int = 0
	princ = 0
	for n in range(num_payments):
		int = r * bal
		princ = c - int
		bal -= princ
	return 'num_payment {:0.0f} c {:0.0f} princ {:0.0f} int {:0.0f} balance {:0.0f}'.format(num_payments, c, princ, int, bal)


def amort(rate, bal, term, num):
	c = bal * rate / 1200 / (1 - (1 + rate / 1200) ** (-term))
	for i in range(num):
		int = bal * rate / 1200
		bal = bal + int - c
	return 'num_payment %d c %.0f princ %.0f int %.0f balance %.0f' % (num, c, c - int, int, bal)


def amort(rate, bal, term, num_payments):
	r = rate / 1200
	c = r * bal / (1 - (1 + r) ** (-term))
	for _ in range(num_payments):
		_int = bal * r
		princ = c - _int
		bal -= princ
	return 'num_payment {} c {:.0f} princ {:.0f} int {:.0f} balance {:.0f}'.format(num_payments, c, princ, _int, bal)


def amort(r, p, n, x):
	r = r / 12 / 100
	c = r * p / (1 - (1 + r) ** (-n))
	curr = p * (1 + r) ** x - ((1 + r) ** x - 1) * (c / r)
	i = r * (p * (1 + r) ** (x - 1) - ((1 + r) ** (x - 1) - 1) * (c / r))
	return f'num_payment {x} c {round(c)} princ {round(c - i)} int {round(i)} balance {round(curr)}'


amort = lambda r, b, t, n, c=0, p=0, i=0, m=-1: m < 0 and amort(r / 1200, b, t, n, r / 1200 * b / (1 - (1 + r / 1200) ** (-t)), p, i, 0) or (m == n and 'num_payment %d c %.0f princ %.0f int %.0f balance %.0f' % (n, c, p, i, b)) or amort(r, r * b + b - c, t - 1, n, c, c - r * b, r * b, m + 1)


def amort(r, b, t, n):
	r /= 1200
	c = r * b / (1 - (1 + r) ** (-t))
	for i in range(n):
		(I, p, b) = (r * b, c - r * b, r * b + b - c)
	return 'num_payment %d c %.0f princ %.0f int %.0f balance %.0f' % (n, c, p, I, b)