MIT6_0001F16_ps1
ps1a
首先根据投资回报以及工资等资金变化情况,通过循环模拟每个月的储蓄变化情况,得出买房需要多少个月,具体程序解析看程序里的注释
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 15 20:50:56 2019
@author: Ding
"""
# 提示用户输入年薪、存款率以及房子总价
string1=input("Enter your annual salary: ")
annual_salary=int(string1) #将字符串转化为数字
string2=input("Enter the percent of your salary to save, as a decimal: ")
portion_saved=float(string2) #将小数转化为float
string3=input("Enter the cost of your dream home: ")
total_cost=int(string3) #将输入的数字转化为int
# print (annual_salary,portion_saved,total_cost)
portion_down_payment=0.25 #首付占总价的比例
payment=portion_down_payment*total_cost #payment表示首付价钱
r=0.04 #年利率
month=0 #从第0个月开始
current_savings=0
while current_savings<payment: #如果仍旧买不起,则继续循环
month+=1 #过了一个月
current_savings=current_savings+current_sa

这篇博客主要解析了MIT6_0001F16_ps1的三个部分:ps1a涉及根据投资回报和工资变化计算买房所需月数;ps1b在ps1a基础上增加工资半年一次的涨幅;ps1c讨论如何在3年内通过特定工资和存款策略支付100W房价的首付。代码中包含了详细的注释来解释实现逻辑。
最低0.47元/天 解锁文章
1656

被折叠的 条评论
为什么被折叠?



