python - 必须多次输入负数才能跳出循环
问题描述
这是我编写的一段代码,除了 else 分支外,它按预期工作。我必须在没有 y 的情况下输入 3 次才能成功进入该分支。有谁明白为什么会这样?
def marker_question(position, marker_position):
invalid_input = True
while invalid_input:
write("Would you like to do anything with the marker?")
answer = input().lower().strip()
if "y" in answer:
write("Would you like to pick it up and place it or would you like to teleport to it?")
answer = input().lower().strip()
if "pick" in answer or "place" in answer:
marker_position = position
invalid_input = False
elif "teleport" in answer:
position = marker_position
invalid_input = False
else:
write("That is not a possible action")
else:
write("You have decided to do nothing with the marker")
invalid_input = False
return position, marker_position
解决方案
推荐阅读
- ethereum - 为什么以太坊钱包允许在合约异常的情况下确认交易?可以预防吗?
- spring - 自定义请求/响应对象中的 MultipartFile
- c# - System.Text.Json:当 json 配置具有通用 JsonStringEnumConverter 时,如何将单个枚举序列化为数字
- javascript - mongodb与nodejs中的多阶段关系
- .net - Azure.Messaging.ServiceBus 无法配置 TransportType
- node.js - wss nodejs如何过滤结果?
- r - 基于合并向量将代码重新编码为二分代码
- git - 为什么在打开 Visual Studio 19 并占用 20% CPU 时运行 git.exe?
- pandas - 如何计算熊猫中空值的平均值?
- c# - C# - 屏幕分辨率不适用于 Selenium Chrome Web 驱动程序