一个青蛙从井底往上爬,第1分钟爬上去4米,下一分钟滑下去2米,请问需要多少分钟能爬出井口?
def climb(upspeed,downspeed,hight):
t,h = 0,0
while True: #h <= hight:
h += upspeed
t += 1
if h >= hight: return t, h
# 条件判断语句为何放在这里?
h -= downspeed
t += 1
upspeed,downspeed,hight = 4,2,50
print(climb(upspeed,downspeed,hight))
(47, 50)
条件判断语句放在其他地方试试看
本文由mdnice多平台发布
网友评论