首页 > 解决方案 > 如果语句没有被评估?Python

问题描述

这是代码:

# 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 semi­annual raise, as a decimal:​ .03

Number of months:​ 142

标签: pythonpython-3.x

解决方案


monthly_savings申请后需要重新评估semi_annual_raise


推荐阅读