蜗牛落在125厘米井的底部。蜗牛每天上升30厘米。但是到了晚上,由于墙壁潮湿,所以在睡觉时会滑动20厘米。从井中逃脱需要多少天?
答案 0 :(得分:0)
well = 125
cmPerDay = 30
cmPerNight = -20
snailHasNotEscaped = True
days = 0
totalCMs = 0
cmPerWholeDay = cmPerDay + cmPerNight
while snailHasNotEscaped:
totalCMs += cmPerWholeDay
days += 1
print(days)
if totalCMs >= well:
snailHasNotEscaped = False
print("Congratulations! the snail escaped in", days, "days")