Dec-16-2018, 01:37 PM
I found a sample question where I have to calculate how long it will take someone to save for a down payment for a mortgage (https://ocw.mit.edu/courses/electrical-e...16_ps1.pdf).
The part that I'm stuck on is where I have to increase wages every 6 months by a percentage. For some reason, the code that I have written doesn't increase wages every 6 months. Please see the link above for the question (part B: saving with a raise) and the code below for my attempt.
Any help will be greatly appreciated
The part that I'm stuck on is where I have to increase wages every 6 months by a percentage. For some reason, the code that I have written doesn't increase wages every 6 months. Please see the link above for the question (part B: saving with a raise) and the code below for my attempt.
Any help will be greatly appreciated
total_cost = float(input("Enter the price of the house: ")) portion_down_payment = 0.25 current_savings = 0 apr = 0.04 semiannual_raise = (1 + float(input("Enter your semi annual raise: "))) r = apr/12 annual_salary = float(input("Enter your annual salary: ")) portion_saved = float(input("Enter the portion you save: ")) monthly_salary = (annual_salary/12)*1 monthly_saved = monthly_salary*portion_saved month = 0 down_payment = total_cost*portion_down_payment while down_payment > current_savings: if month % 6 == 0: annual_salary = annual_salary*semiannual_raise current_savings = current_savings + monthly_saved compound = (1 + r) current_savings = current_savings*compound month += 1 years = month/12 print("Amount saved per month: " + str(monthly_saved)) print("Total amount saved: " + str(current_savings)) print("Total time taken: " + str(month) + " months or " + str(years) + " years.")