为什么使用大写Right的while循环未运行?

问题描述 投票:-2回答:1

下面是我的代码:

    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.x boolean-operations or-operator
1个回答
2
投票

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

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

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

它将像这样工作:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.