喜欢溜溜球的螺狮粉ssp到手了:硬核,跟社招没区别吧
投递百度等公司8个岗位 >
0 点赞 评论 收藏
分享
2020-05-30 07:15
University of California San Diego 算法工程师 0 点赞 评论 收藏
分享
吃饭旅行_走走停停:'''
https://www.nowcoder.com/discuss/170710?type=0&order=0&pos=17&page=1
原题一字不差如下
“某城市一套房两百万,每年固定升值10%,假定你是一名程序员,每年年薪固定40w元,假设你不吃不喝无消费,请问工作多少年你可以买一套房?”(摔
'''
house_price = 2.e6
annual_salary = 4.e5
deposit = 0
def iteration_house(hp):
return hp*1.10
def sudden_death():
rate=1e-2
import random
if random.randint(0,100)/100 < rate:
print('oh, You suddenly died.....')
return True
return False
def buy_house():
print('Finally, I got a house.')
year_cnt=1
while not sudden_death():
if house_price - deposit < 0:
buy_house() ; break
house_price = iteration_house(house_price)
deposit += annual_salary
print('house_price=%-9.0f'%house_price,'deposit=%-9.0f'%deposit,'year_cnt=%-4d'%year_cnt)
year_cnt+=1
output: house_price=2200000 deposit=400000 year_cnt=1
house_price=2420000 deposit=800000 year_cnt=2
house_price=2662000 deposit=1200000 year_cnt=3
house_price=2928200 deposit=1600000 year_cnt=4
house_price=3221020 deposit=2000000 year_cnt=5
house_price=3543122 deposit=2400000 year_cnt=6
house_price=3897434 deposit=2800000 year_cnt=7
house_price=4287178 deposit=3200000 year_cnt=8
house_price=4715895 deposit=3600000 year_cnt=9
house_price=5187485 deposit=4000000 year_cnt=10
house_price=5706233 deposit=4400000 year_cnt=11
house_price=6276857 deposit=4800000 year_cnt=12
house_price=6904542 deposit=5200000 year_cnt=13
house_price=7594997 deposit=5600000 year_cnt=14
house_price=8354496 deposit=6000000 year_cnt=15
house_price=9189946 deposit=6400000 year_cnt=16
house_price=10108941 deposit=6800000 year_cnt=17
house_price=11119835 deposit=7200000 year_cnt=18
house_price=12231818 deposit=7600000 year_cnt=19
house_price=13455000 deposit=8000000 year_cnt=20
house_price=14800500 deposit=8400000 year_cnt=21
house_price=16280550 deposit=8800000 year_cnt=22
house_price=17908605 deposit=9200000 year_cnt=23
house_price=19699465 deposit=9600000 year_cnt=24
house_price=21669412 deposit=10000000 year_cnt=25
house_price=23836353 deposit=10400000 year_cnt=26
house_price=26219988 deposit=10800000 year_cnt=27
house_price=28841987 deposit=11200000 year_cnt=28
house_price=31726186 deposit=11600000 year_cnt=29
house_price=34898805 deposit=12000000 year_cnt=30
house_price=38388685 deposit=12400000 year_cnt=31
house_price=42227553 deposit=12800000 year_cnt=32
house_price=46450309 deposit=13200000 year_cnt=33
oh, You suddenly died.....
[Finished in 0.3s]
0 点赞 评论 收藏
分享
创作者周榜
更多
关注他的用户也关注了: