以下是代码:
# Inputs
annual_salary = float(input('what is your annual salary? >> '))
portion_saved = float(input('How much of your salary do you want to put away each month? >> '))
total_cost = float(input('what is the price of your dream home? >> '))
semi_annual_raise = float(input('Enter a semi_annual raise? >> '))
# Global Variables
current_savings = 0
r = .04
monthly_return = (current_savings*r)/12
number_of_months = 0
portion_down_payment = total_cost*.25
monthly_savings = (annual_salary/12)*portion_saved
while current_savings < portion_down_payment:
current_savings = current_savings + monthly_savings + ((current_savings*r)/12)
number_of_months += 1
if number_of_months%6 == 0:
annual_salary = annual_salary + (annual_salary * semi_annual_raise)
print(number_of_months)
所有这一切应该是评估大约几个月,直到达到一定的节省金额。每半年举行一次。
我错过了什么?
预期结果的示例:
Enter your starting annual salary: 120000
Enter the percent of your salary to save, as a decimal: .05 Enter the cost of your dream home: 500000
Enter the semiannual raise, as a decimal: .03
Number of months: 142
答案 0 :(得分:2)
您需要在应用monthly_savings
semi_annual_raise