这是我编写的一段代码,除了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