首页 > 解决方案 > 这个 if else 语句和打印的问题在哪里?

问题描述

我试图理解我正在做的这个测试练习。我写了下面的代码,它被执行了,但是,结果并不是我真正想要的。第一个 if 语句应该根据经过的天数打印一天或几天。最后一个打印,解决方案,应该打印天加上文本之间有一个空格,但是,我不能做到这一点。提前致谢!

well_height = 125
daily_distance = 30
nightly_distance = 20
snail_position = 0
notEscaped = True

# Create a variable days to keep
# count of the days that pass until the snail escapes the well

days = 0

fullDaylydist = daily_distance - nightly_distance

while snail_position < well_height:
    if days <= 1:
        print(str(days) + " day gone")
    else:
        print(str(days) + " days gone")
    snail_position += fullDaylydist
    if snail_position < well_height:
        days += 1
# Print the solution.
    else:
        print(str(days) + " days and I am out from the well!")

标签: python-3.x

解决方案


第一个 if 是小于或等于 1 的天数。你的意思是这个还是应该说大于或等于一个> =


推荐阅读