Introduction to Computer Science and Programming in Python (Fall 2016)是ocw.mit的课程6.0001,作业没有答案,有些program可以参考以前课程的作业的思路。代码是去年写下,稍作整理以记录。
part A: House Hunting
annual_salary = int(input("Enter your annual salary: "))
portion_saved = float(input("Enter the percent of your salary to sace,as a decimal: "))
total_cost = int(input("Enter the cost of your dream home: "))
r = 0.04
monthly_salary = annual_salary/12
portion_down_payment = 0.25
cost= total_cost * portion_down_payment
#initialize state variables
num_month=1
current_savings=0
current_savings += monthly_salary*portion_saved
while current_savings < cost:
current_savings += current_savings*r/12
current_savings += monthly_salary*portion_saved
num_month += 1
print("Number of months:", num_month)
Part B: Saving, with a raise