PSet_1a - Baseline
This prompts the user for the cost of their dream house, their salary, the portion of their monthly salary that they are willing to save, and returns the number of months it would take for them to have a down payment (25% of the cost of their dream house)
total_cost = float(input('How much is the dream house? '))
portion_down_payment = 0.25
current_savings = 0
r = 0.04
annual_salary = float(input('What is your salary? '))
portion_saved = float(input('What is the amount saved per month? '))
monthly_salary = annual_salary / 12.0
amount_down_payment = total_cost * portion_down_payment
portion_amount = monthly_salary * portion_saved
months = 0
while current_savings <= amount_down_payment:
current_savings += portion_amount + (current_savings * (r / 12))
months += 1
print(current_savings, months)
PSet_1b - Adjusted for Semi-Annual Raise
Prompts the user as the same above but this one asks for a semi annual rate, turns it into a number to add to the annual raise.
total_cost = float(input('How much is the dream house? '))
portion_down_payment = 0.25
current_savings = 0
r = 0.04
annual_salary = float(input('What is your salary? '))
portion_saved = float(input('What is the amount saved per month? '))
semi_annual_rate = float(input('What is the rate of your semi-annual_raise? '))
monthly_salary = annual_salary / 12.0
semi_annual_raise = monthly_salary * semi_annual_rate
amount_down_payment = total_cost * portion_down_payment
portion_amount = monthly_salary * portion_saved
months = 0
while current_savings <= amount_down_payment:
months += 1
if months % 6 == 0:
annual_salary += semi_annual_raise
current_savings += portion_amount + (current_savings * (r / 12))
print(current_savings, months)
Both programs return the same results when I run them and I have been trying to figure out why and how on my own for a few hours now without much improvement.
Aucun commentaire:
Enregistrer un commentaire