google面试题:现在北京有一套房子,价格200万,假设房价每年上涨10%,一个软件工程师每年固定能赚40万。他想买这套房子,不贷款,不涨工资,没有其他收入,不吃不喝不消费,需要几年能攒够钱买这套房子? A, 5年 B, 7年 C, 8年 D, 9年 E, 永远买不起
1 #coding=utf8
2
3 price = 200 * 10000 #初始房价
4 growth_rate = 1 + 0.1 #增长率
5 max_year = 100 #最多等多少年
6 income = 50 * 10000 #年收入
7 deposit = 0 #存款
8
9 for year in range(max_year):
10 price *= growth_rate
11 deposit += income
12 if deposit > price:
13 print year, '^_^'
14 break
15 else:
16 print year, 'T_T'
浙公网安备 33010602011771号