-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhouse_hunting_2.py
50 lines (45 loc) · 1.45 KB
/
house_hunting_2.py
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
def calculate_months(salary, saved, cost, bonus):
portion_down_payment = .25
down_payment = portion_down_payment * cost
current_savings = 0
r=0.04
raise_counter = 1
months = 0
monthly_salary = salary / 12
ammount_saved = monthly_salary * saved
while current_savings < down_payment:
if raise_counter == 5:
salary *= 1+bonus
monthly_salary = salary / 12
raise_counter = 0
# Calculate ammount_saved based on the NEW salary
ammount_saved = monthly_salary * saved
else:
raise_counter += 1
current_savings += ammount_saved + (current_savings * r / 12)
months += 1
return months
def testcase1():
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)
def testcase2():
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)
def testcase3():
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)
testcase1()
testcase2()
testcase3()