-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject-4.qmd
162 lines (125 loc) · 5.47 KB
/
project-4.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
---
title: "Programming Project 4"
---
```{r}
#| echo: false
#| message: false
#| warning: false
library(tidyverse)
library(readxl)
assignments <- read_excel("assessment_schedule.xlsx") %>%
mutate(formatted_date = format(due_date, "%A, %B %d, %Y"))
```
Programming Projects are to be submitted to [gradescope](https://www.gradescope.com/courses/934148).
**Due date: `r assignments %>% filter(assessment == "Programming Project 4") %>% pull(formatted_date)` at 9pm**
This assignment is an adaptation of the [MIT's 6.0001 Introduction to Computer Science and Programming in Python programming set 1](https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/resources/mit6_0001f16_ps1/).
Make sure you follow the provided [style guide](style.html) (you will be graded on it!).
Also make sure you check the [Academic Integrity](academic-integrity.html) and [Common Gradescope Errors](gradescope-errors.html) pages.
# House Hunting
You have graduated and now have a great job and decide that you want to start saving to buy a house. As housing prices are very high in the US right now, you realize you are going to have to save for several years before you can afford to make the down payment on a house.
## Part 1
Name the program `house_hunting_1.py`. Make sure that gradescope gives you the points for passing the test cases.
In this assignment we are going to determine how long it will take you to save enough money to make the down payment given the following assumptions:
1. Call the cost of your first home `total_cost`.
2. Call the portion of the cost needed for a down payment `portion_down_payment` . For
simplicity, assume that `portion_down_payment = 0.25 (25%)`.
3. Call the amount that you have saved thus far `current_savings`. You start with a current
savings of $0.
4. Assume that you invest your current savings wisely, with an annual return of r (in other words,
at the beginning of each month, you receive an additional `current_savings*r/12` funds to put into
your savings – the 12 is because r is an annual rate). Assume that your investments earn a
return of r = 0.04 (4%).
5. Assume your annual salary is `annual_salary` .
6. Assume you are going to dedicate a certain amount of your salary each month to saving for
the down payment. Call that `portion_saved`. This variable should be in decimal form (i.e. 0.1
for 10%).
7. At the end of each month, your savings will be increased by the return on your investment,
plus a percentage of your monthly salary (annual salary / 12).
Write a program to calculate how many months it will take you to save up enough money for a down
payment.
### Test cases -- Part 1
Try different arguments and see how long it takes to save for a down payment. Please make your
program print results in the format shown in the test cases below.
#### Test Case 1
```{python}
#| eval: false
#| echo: true
annual_salary = 120000
portion_saved = .1
total_cost = 1000000
total_months = calculate_months(annual_salary, portion_saved, total_cost)
print("Number of months:", total_months)
```
<pre>
Number of months: 183
</pre>
#### Test Case 2
```{python}
#| eval: false
#| echo: true
annual_salary = 80000
portion_saved = .15
total_cost = 500000
total_months = calculate_months(annual_salary, portion_saved, total_cost)
print("Number of months:", total_months)
```
<pre>
Number of months: 105
</pre>
## Part 2
Name the program `house_hunting_2.py`. Make sure that gradescope gives you the points for passing the test cases.
In Part 1, we unrealistically assumed that your salary didn’t change. So we are going to build on your
solution to Part 1 by factoring in a raise every six months.
In `house_hunting_2.py`, copy your solution to Part 1 (as we are going to reuse much of that machinery). Modify your program to include the following:
1. Use a variable for a semi-annual salary raise semi_annual_raise (as a decimal percentage)
2. After the 6th month, increase your salary by that percentage. Do the same after the 12th
month, the 18 month, and so on.
Write a program to calculate how many months it will take you save up enough money for a down
payment. Like before, assume that your investments earn a return of r = 0.04 (or 4%) and the
required down payment percentage is 0.25 (or 25%).
Be careful about when you increase your salary – this should only happen after the 6th, 12th, 18th month, and so on.
### Test cases -- Part 2
Try different arguments and see how long it takes to save for a down payment. Please make your
program print results in the format shown in the test cases below.
#### Test Case 1
```{python}
#| eval: false
#| echo: true
annual_salary = 120000
portion_saved = .05
total_cost = 500000
semi_annual_raise = .03
total_months = calculate_months(annual_salary, portion_saved, total_cost, semi_annual_raise)
print("Number of months:", total_months)
```
<pre>
Number of months: 142
</pre>
#### Test Case 2
```{python}
#| eval: false
#| echo: true
annual_salary = 80000
portion_saved = .1
total_cost = 800000
semi_annual_raise = .03
total_months = calculate_months(annual_salary, portion_saved, total_cost, semi_annual_raise)
print("Number of months:", total_months)
```
<pre>
Number of months: 159
</pre>
#### Test Case 3
```{python}
#| eval: false
#| echo: true
annual_salary = 75000
portion_saved = .05
total_cost = 1500000
semi_annual_raise = .05
total_months = calculate_months(annual_salary, portion_saved, total_cost, semi_annual_raise)
print("Number of months:", total_months)
```
<pre>
Number of months: 261
</pre>