Click here to Skip to main content
14,026,083 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Dream house
Write a program that calculates how long it would take you to save enough money to pay the down payment for your dream house. You will ask the user for their annual salary, the percent of the salary they’d want to save, and the cost of their dream home.

You should assume that the down payment is 25% of the total cost of the home. The time should be expressed in months. Hint: annual salary / 12 will give you the monthly salary.

Part 1 - Get a raise
Use your code from the previous part as a starting point.

Extending the calculator from the last question, lets assume (accurately so) that you get a raise about twice year (every six months). Keeping this in mind, prompt the user for a semi-annual raise percentage (which will apply every six months) For example, if you start at 100,000 and get a 5% raise every six months, your salary for the first six months would be 8,333.33/month(base $100,000), and 8,750/month (base $105,000) for the following six months, and so on…

Sample output 1:

What's your annual salary? 120000
What percent of your salary will you save? 10%
How much does your dream home cost? 1000000
What's the semi-annual raise percentage? 0
What's the investment annual return? 4

You would have to work for 183 months to afford the downpayment for your dream house.
183 months or 15 years and 3 months.
Sample output 2:

What's your annual salary? 150000
What percent of your salary will you save? 10
How much does your dream home cost? 500000
What's the semi-annual raise percentage? 3%
What's the investment annual return? 4%

You would have to work for 75 months to afford the downpayment for your dream house.
75 months or 6 years and 3 months.

Sample output 3:

What's your annual salary? 120000
What percent of your salary will you save? 10%
How much does your dream home cost? 1000000
What's the semi-annual raise percentage? 0
What's the investment annual return? 0%

You would have to work for 250 months to afford the downpayment for your dream house.
250 months or 20 years and 10 months.

Part 2 - Build some savings

You can reuse some of your code from the previous part.

The previous questions focused on how long you would have to work to afford the downpayment. In this question, you’re going to answer the reverse - how much would I have to save to be able to afford the downpayment in X years.

We can iron out some details prior, to make this easier: The semi-annual raise will be 7% The investments have an annual return of 4% The downpayment for the house will be 25% The dream house costs $1m.

For this question, you should find the best rate of savings so that the $1m downpayment can be paid in 3 years (36 months), given the user’s salary.

Sample run 1:

What's your annual salary? 120000
What percent of your salary will you save? 10%
How much does your dream home cost? 1000000
What's the semi-annual raise percentage? 0
What's the investment annual return? 4

You would have to work for 183 months to afford the downpayment for your dream house.
183 months or 15 years and 3 months.

How many years are you planning to save for downpayment? 3
The best savings rate for you is 0.6548.

Sample run 2:

What's your annual salary? 150000
What percent of your salary will you save? 120
What percent of your salary will you save? 12%
How much does your dream home cost? 500000
What's the semi-annual raise percentage? -3%
What's the semi-annual raise percentage? 3%
What's the investment annual return? 7%

You would have to work for 62 months to afford the downpayment for your dream house.
62 months or 5 years and 2 months.

How many years are you planning to save for downpayment? 4
The best savings rate for you is 0.1639.

Sample run 3:

What's your annual salary? 150000
What percent of your salary will you save? 10%
How much does your dream home cost? 1000000
What's the semi-annual raise percentage? 7%
What's the investment annual return? 4

You would have to work for 99 months to afford the downpayment for your dream house.
99 months or 8 years and 3 months.

How many years are you planning to save for downpayment? 3
The best savings rate for you is 0.4411.

What I have tried:

Here is the code that I used for part 1 -

salary = int(input("What is you annual salary? "))
sav_percent = int(input("What percent of your salary will you save? "))

monthly_sal = salary/12                                     # calculating monthly salary
saving = 0                                                  # initial savings

cost = int(input("How much does your dream home cost? "))
dwn_pymt = (0.25)* cost                                     # to calculate the down payment of the dream home 

months_of_saving = 0
raise_percent = int(input("What's the semi-annual raise percentage? "))

annual_ret = (int(input("What's the investment annual return? "))/100)

while saving < dwn_pymt:
    saving += (saving * (annual_ret/12))                    # this will add the montly interest of investement into savings
    saving += ((sav_percent/100) * monthly_sal)             # this will add the percent of monthly income that user want to save 
    months_of_saving += 1                                   # to increment the months of saving by 1
    if months_of_saving % 6 == 0:                           # to check for the semi monthly increment
        salary = salary + (salary * (raise_percent/100))
        monthly_sal = salary/12
    #print(round(salary))
    #print("Total no. months {}, Total amount that will be saved {}.".format(months_of_saving,round(saving)))
        
print("\n")
print("You would have to work for {} months to afford the downpayment for your dream house.".format(months_of_saving))

print("{} months or {} years and {} months".format(months_of_saving, (months_of_saving//12), (months_of_saving%12)))
Posted
Comments
Gerry Schmitz 23-Mar-19 16:40pm
   
Formulate a "question" ... we don't read your xxx and figure out what's "missing".
Rahul VB 27-Mar-19 10:16am
   
Exactly correct. Agreed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190419.4 | Last Updated 23 Mar 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100