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:
- The value of the dream host should be set when the program starts:
total_cost
- 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
) - The amount you have currently saved can be modeled in a single variable (
current_savings
) - 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%). - Assume the annual salary is annual salary.
- Assume you are going to dedicate a certain amount of your salary each month to saving of the down payment. Call that
portion_saved
. - 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:
- The starting annual salary:
annual_salary
- The portion of the salary to be saved:
portion_saved
- The cost of the dream home:
total_cost
Hints
- Organize your program into the following sections: input, process, iteration
- 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
Comments
Loading
No results found