-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem Set 1B
More file actions
59 lines (55 loc) · 3.03 KB
/
Problem Set 1B
File metadata and controls
59 lines (55 loc) · 3.03 KB
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
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 11 16:32:59 2022
@author: vixey foxwish
"""
# See Problem Set 1A file for prior context
# Part B: Saving, with a raise
# In Part A, we unrealistically assumed that your salary didn't change. But
# clearly you are going to be worth more to your company over time. So we are
# going to build on your solution to Part A by factoring in a raise every six
# months. In ps1b.py, copy your solution to Part A (as we are going to reuse
# much of that machinery.) Modify your program to include the following:
# 1. Have the user input 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, 18th month, and so on.
# Write a program to calculate how many months it will take you to save up enough
# money for a down payment. Like before, assume that your investments earn a return
# of r = 0.04
# my note: (simplified, non-adjusted approximated monthly return of .04/12)
# and the required down payment percentage is 0.25 or 25%. Have the user enter
# the following variables:
# 1. The starting annual salary (annual_salary) 2
# 2. The percentage of salary to be saved (portion_saved)
# 3. The cost of your dream home (total_cost)
# 4. The semiannual salary raise (semi_annual_raise)
portion_down_payment = 0.25
r = 0.04
current_savings = 0
month_count = 0
annual_salary = float(input("Enter your annual salary: \n"))
portion_saved = float(input("Enter the percent of your salary to save, as a decimal: \n"))
total_cost = float(input("Enter the cost of your dream home: \n"))
semi_annual_raise = float(input("Enter the semi-annual raise, as a decimal: \n"))
down_required = portion_down_payment*total_cost
monthly_unadjusted_return = r/12
# This doesn't account for true r compounding 1.04^(1/12) and is just .04/12 monthly instead
while current_savings < down_required:
month_count += 1
# This starts the month increment increasing by 1 before end of the month changes
monthly_gain = current_savings*monthly_unadjusted_return
# This is the gain caused by the monthly return on previously saved funds
current_savings += monthly_gain
monthly_contribution = annual_salary*(1/12)*portion_saved
# This is the newly added money from the salary being added at end of month
# (There hasn't been any time elapsed for investment gains, so it comes separately)
current_savings += monthly_contribution
# Note that semi-annual raise can only take effect "AFTER" the 6th/12th/18th/etc. month
if (month_count%6 == 0):
# Code checks that number of months elapsed by now is evenly divisible by 6, then *= applies raise
annual_salary *= (1+semi_annual_raise)
print("Number of months: ", month_count)
# Verified that (120,000; .05; 1,000,000; .03) returns 142 months as in HW answers
# Verified that (80,000; .1; 800,000; .03) returns 159 months as in the HW answers
# Verified that (75,000; .05; 1,500,000; .05) returns 261 months as in the HW answers