python-3.x - 这个 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!")
解决方案
第一个 if 是小于或等于 1 的天数。你的意思是这个还是应该说大于或等于一个> =
推荐阅读
- javascript - 读取目录中的文件夹数(WEB)
- xamarin - Xamarin iOS:源文件不是有效的 UTF-8
- python - 垂直堆叠二维数组
- oracle - 字符串到时间戳转换plsql
- spring-boot - 尝试启动从分层战争创建的 docker 映像时出现 ClassNotFoundException
- jquery - 使用 jquery 切换 Woocommerce 类别过滤器
- node.js - koa 应用程序的 Jest 测试收到错误为“TypeError:app.address 不是函数”
- javascript - 如何使用突变改变 vuex 状态
- flutter - 方法填充后如何返回列表,颤振
- python - 用于结束在列表中查找项目的循环的良好 Python 编程实践