python - 如果语句没有被评估?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 semiannual raise, as a decimal: .03
Number of months: 142
解决方案
monthly_savings
申请后需要重新评估semi_annual_raise
推荐阅读
- vhdl - VHDL Quartus 无法识别“+”和“-”
- javascript - Firebase 函数:更新集合中的所有文档
- c# - Angular 7 AES 使用 crypt-js 加密密码
- python - BigQuery 上传 API - 有没有添加多个 nullMarker 的方法?
- f# - 在 fsi 中显示函数的文档
- java - 如何检查缓存何时为空,我应该加载它
- django - 如何在 Django 中识别或记住用户的浏览器
- c# - PlatformNotSupportedException:以下构造函数参数没有匹配的夹具数据
- heroku - 用于 Heroku-18 堆栈的 Imagemagick buildpack
- flutter - 每次flutter应用打开时如何请求gps权限?