必须多次输入负数才能退出循环

时间:2018-09-05 03:02:00

标签: python python-3.x

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

这是输入/输出的示例图像 Test

1 个答案:

答案 0 :(得分:1)

我不确定是什么问题,但是请尝试使用引号输入 对我有用 enter image description here

检查输入功能是否正确使用

相关问题