COMP 141: Project 1

Car Loan Calculator

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

There are a number of factors involved with a car loan. There's an initial sales price for the car, on which the buyer must pay sales tax. Often the buyer will be trading in a previous vehicle and this amount (trade-in value) is deducted from the purchase price before tax is added. Often the buyer will pay some amount of money upfront as a down payment. This amount is deducted after tax is added. The remainder of the purchase price (the amount left over after the down payment and trade-in value is taken away) becomes the principal value of the loan (the amount that the person must borrow).

From this principal, the car buyer 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 = the principal, r = the interest rate, and m = the number of monthly payments.

Here's an example:

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. Your comment should look like the standard program header shown here, but ignore the part at the end where it talks about functions, since we haven't learned about those yet. Write the program so that it does the following: 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)
Welcome to the car loan calculator.
Please enter the following to determine your monthly payment.
Purchase price of car: 25000
Trade-in value: 3000
Sales tax rate (enter 9.25% as 9.25): 9.25
Down payment amount: 2000
The principal value of your loan will be 22035.0
Number of years loan will last: 5
Interest rate of loan: 3.5
You will make 60 payments of 400.8551004195982
Over 5 years, this will be a total of 24051.306025175894
(Program ends)

Test 2

(Program begins)
Welcome to the car loan calculator.
Please enter the following to determine your monthly payment.
Purchase price of car: 15000
Trade-in value: 2500
Sales tax rate (enter 9.25% as 9.25): 6.5
Down payment amount: 1000
The principal value of your loan will be 12312.5
Number of years loan will last: 7
Interest rate of loan: 5.5
You will make 84 payments of 176.93115014527436
Over 7 years, this will be a total of 14862.216612203047
(Program ends)
Your code does not need to follow this script verbatim, but all the mentioned functionality should work as shown.

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.

How to get started

  • Create a Python program named mortgage_yourLastName_yourFirstName.py
  • Follow the instructions for commenting your code. You can ignore the part at the end about functions, as we haven't learned those yet.
  • 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.
  • Use appropriate variable naming conventions.
  • Include code that is commented appropriately, is neatly and clearly formatted, and includes proper use of white space. (This means using blank lines to break up your program into sections, using spaces appropriately to make your code readable, and not making the lines of your program too long.)
  • Submitting your project

    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 (though 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.

    A maximum of five bonus points may be obtained through any combination of challenge problems and early submissions. Furthermore, these bonus points will only compensate for up to five points lost through grading penalties elsewhere in your code. For instance, suppose you turn in your code three days early (+3 points) and complete a challenge problem worth three points. This is 6 total points, but bonus points are capped at 5. Suppose you lose 10 points for a mistake in your program. Your final grade will be 95.