In
this section, you will use strings and numbers to make a useful program. This
program calculates how much money you will pay on a loan with a certain
interest rate.
If you borrow an amount of money X, at an annual rate R, and you pay it back over N months, there is an equation to calculate the monthly payment. It is a big, ugly equation:
This
is a huge pain to enter into a calculator.
It
is not very much fun to enter into Python, either, so just this once, you can
copy and paste the calculation from the program below.
We
are going to calculate a loan of $10,000 at 5.25 percent, for 72 months.
Create a new Python file, type the following and run it:
You
should see this output:
This
program calculates how much money you will pay on a loan.
If
you borrow 10000 dollars and pay it back over 72 months at an
annual
interest rate of 5.25 percent, your monthly payment will be:
162.211537477
Your
total payable will be:
11679.2306983
Congratulations!
You have written a program that can do something useful for you. In the next
section, we will modify it to make it a little more powerful.