首页 > 解决方案 > 为什么大写 Right 的 while 循环没有运行?

问题描述

下面是我的代码:

    name = input ('Whats ur name ? ')

    dtion = input (name + ' you are in the forest where do u wanna go? ')

    while dtion != "right" or dtion != "Right":

       dtion = input ("you are still in the Forest where do u wanna go? ")  

    print ("You are out of the Forest")

标签: python-3.xboolean-operationsor-operator

解决方案


您编写的条件永远不会变为假,因为 dtion 对于其中一个条件始终为真,因此整体条件始终为真。

您正在寻找的条件是这样的:

while not (dtion == "right" or dtion == "Right"):

它将像这样工作:

在此处输入图像描述


推荐阅读