COMP 141: Project 1

Mortgage Calculator

In this project, you will write a program to calculate information about a mortgage for buying a home. Often a house is too expensive to purchase outright, so people will obtain a loan, or a mortgage, by which they pay off the house over a period of years.

There are a number of factors involved with a mortgage. The house initially sells for some purchase price. The buyer will pay some amount of money upfront, before the loan, as a down payment. This is usually a percentage of the initial purchase price, like 5%, 10%, or 20%. The remainder of the purchase price (the amount left over after the down payment is taken away) becomes the principal value of the loan (the amount that the person must borrow).

From this principal, the homebuyer negotiates with a lender an interest rate for the loan and the amount of time in years over which the loan will be repaid. There is a particular formula used to calculate the monthly payment of the loan:

       P ( r / 12 )
-------------------------
                     -m 
  (1 - ( 1 + r / 12 )   )
where P = is the principal, r = the interest rate, and m = the number of monthly payments.

Here's an example. Suppose you are interested in buying a house that costs $250,000. $250,000 is the purchase price. You put down 20% as a down payment. So your down payment is 20% of $250,000, or $50,000. The remainder, $200,000 becomes the principal for your loan. Suppose you get a 6.5% interest rate on a 30-year mortgage. You must make a payment every month, which means you'll make 360 payments. The payment each month will be:

      200000 ( 0.065 / 12 )
---------------------------------
                         -360 
  (1 - ( 1 + 0.065 / 12 )     )
which comes out to approximately $1,264.14. Note that r has been converted from a percent to a decimal.

What you need to do

Start a new Python program (in a separate window, not the Python shell). Put a comment at the top with your name and a description of what the program does. Write the program so that it does the following: If you are confused, just make your program act identically to the examples below.

Sample Interactions

What the computer displays (prints) is in regular text, what the user types is in bold, and what the program is doing behind the scenes is in italics.

Test 1

(Program begins)
How much does the house cost? 250000
What percent are you putting down? 20
You are putting down 50000.0 leaving 200000.0 for the mortgage.
How many years does the mortgage last? 30
What is your interest rate? 6.5
You will make 360 payments of 1264.1360469859305
Over 30 years, this will be a total of 455088.976914935
(Program ends)

Test 2

(Program begins)
How much does the house cost? 300000
What percent are you putting down? 15
You are putting down 45000.0 leaving 255000.0 for the mortgage.
How many years does the mortgage last? 20
What is your interest rate? 5.25
You will make 240 payments of 1718.3026241800826
Over 20 years, this will be a total of 412392.6298032198
(Program ends)
Your code does not need to follow this script verbatim, but all the mentioned functionality should work as shown.

How to get started

  • Create a Python program named mortgage_yourLastName_yourFirstName.py
  • Follow the instructions for commenting your code.
  • Submit your Python file on Moodle under Project 1.
  • Requirements

    A good program will do all of the following:

  • Be named correctly.
  • Include the standard program header as a comment at the top of your program.
  • Ask the user for all input using clear and understandable prompts.
  • Display all information using clear and understandable messages.
  • Using appropriate variable naming conventions.
  • Include code that is commented appropriately, is neatly and clearly formatted, and includes proper use of white space.
  • Hints

    Work out some examples on paper first to determine how the math works in this problem. Decide on what variables you need, what they represent in the problem, and what their data types should be. Test your program on lots of examples and make sure the math checks out.

    What to turn in

    Through Moodle, turn in your code as a file called mortgage_yourLastName_yourFirstName.py.

    Challenge Problems

    From time to time, I will offer "challenge problems" on assignments. These problems are designed to have little (but some) impact on your grade whether you do them or not. You should think of these problems as opportunities to work on something interesting and optional, rather than a way to raise your grade through "extra credit."

    Policy on challenge problems:

    Challenge problems for this assignment:

    Grading

    Your program will be graded on correctness (whether your calculations are correct), as well as on coding style, which refers to choices you make when writing your code, such as good use of variable names, appropriate indentation, and comments (this is not an exhaustive list).

    You will receive one bonus point for every complete day your program is turned in early, up to a maximum of five points. For instance, if your program is due on September 20 at 11:59pm, if you turn in your code on Moodle any time on September 19 from 12:00am through 11:59pm, you will receive one extra point on your project. Programs submitted on September 18 from 12:00am through 11:59pm will receive two points. This pattern continues for up to five points.