for循环+if判断,上5,下4的时候各判断一次,看看超没超10m
def up():
count = 0
i = 0
while True:
count += 1
i = i + 5
if i >= 10:
break
i = i - 4
print(count)
return count
count是爬的次数,i是爬的高度
望采纳
# -*- coding:utf-8 -*-
wellDeeper = 10 #井深
climbDistance = 5 #向上爬的高度
wipeDown=4 #向下滑的距离
count = 0 #次数
start = 0 #起始高度
while True:
count += 1 #次数
start += climbDistance #向上爬
if start >= wellDeeper:
break
else:
start -= wipeDown #向下滑
continue
print("共计爬取次数为:",count)