Let’s write a program to calculate the monthly payment and loan balance on amortized mortgages.

$$ Monthly~Payment = \frac{L \times (1+c)^{n}}{(1+c)^n-1} $$ Where

- L = Total amount borrowed
- c = Monthly rate of interest
- n = Number of months

In [11]:

```
###################################################
# Filename : simple_mortgage_calculator #
# Purpose : To demonstrate reading data from #
# screen and use it in a formula. #
# * How to translate algebraic #
# expressions into python expressions #
# #
# Author : Niel S. #
# The English Tea Company LLC #
###################################################
def main():
run_flag = True
while(run_flag == True):
L = input ('Enter an amount: ')
APR = input ('Enter Annual Percentage Rate: ')
N = input ('Enter Duration in years: ')
#Convert the values into floating point numbers.
L = float(L)
c = float (APR)/1200. #convert annual percentage to monthly rate.
n = float (N)*12. #convert number of years to number of months.
#Monthly payment is calculated using a formula.
P = L*(c*(1 + c)**n)/((1 + c)**n - 1)
print ('Monthly Payment: ',round(P,0))
rflag = input('Do you wish to enter another amount (Y for Yes):').strip().upper()
if not rflag == 'Y':
run_flag = False
if __name__ == '__main__':
main()
```