Rob Oakes
Nov 20, 2024

Exercise: House Hunting

The only way to get better at a skill is to deliberately practice. (Deliberate practice is a special type of preparation that is specific, purposeful, and mindful of the aspects of a skill where you are weak.) This article is a part of a series introducing programming challenges in the Python programming language to provide opportunities for deliberate practice. Each entry in the series will have two parts, this part introduces the requirements for a program needed to calculate the amount needed for a house down payment. The next will show my solution and walk through the decisions I made while writing it.

House Hunting

You have just accepted a job in the San Francisco Bay area and you want to (eventually) buy a home. Since housing prices are very high in the Bay Area, you want to plan your savings and determine how long you will need to save before you can afford a down payment. To model a few different scenarios, you decide to create a simple program.

Requirements

The assumptions you are currently making are:

  1. The value of the dream host should be set when the program starts: total_cost
  2. Portion of the cost needed for a down payment will also be constant (`portion_down_payment`) and can be set to 25% of the value of the home ( 0.25 )
  3. The amount you have currently saved can be modeled in a single variable ( current_savings )
  4. Assuming that you invest your current savings wisely, with annual return of r (in other words, at the end of each month, you receive an additional current_savings*r/12 payment into your savings as interest). Assume that your investments earn a return of r=0.04 (4%).
  5. Assume the annual salary is annual salary.
  6. Assume you are going to dedicate a certain amount of your salary each month to saving of the down payment. Call that portion_saved.
  7. At the end of the month, the savings will increase by the return on your investment plus a percentage of your monthly salary (annual salary / 12).

Your program should ask for the following variables:

  1. The starting annual salary: annual_salary
  2. The portion of the salary to be saved: portion_saved
  3. The cost of the dream home: total_cost

Hints

  1. Organize your program into the following sections: input, process, iteration
  2. Initialize some state variables to ensure that all values are available at the time you begin iterating

Test Cases

Test Case 1

  • Cost of House: $1 million
  • Annual Salary: $120,000
  • Percent of salary: 0.1
  • Number of months: 183

Test Case 2

  • Cost of House: $500,000
  • Annual Salary: $80,000
  • Percent of salary: 0.15
  • Number of months: 105
Rob Oakes Nov 20, 2024
More Articles by Rob Oakes

Loading

Unable to find related content

Comments

Loading
Unable to retrieve data due to an error
Retry
No results found
Back to All Comments