初学者 - While 循环问题

Beginner - While Loop Troubles

为了学习,我开始学习Python编程语言。

对编程还很陌生,在理解为什么这行不通时遇到了一些困难。

while compReady == False: 
    compAI = input("Which strategy for the computer [1,2,3]? ")
    if compAI == "1" or "2" or "3":
        compReady = True
    elif compAI != "1" or "2" or "3":
        print("Please enter either 1, 2, or 3.")

我遇到的问题是,无论输入什么到compAI,它都贯穿'if'语句。感谢任何帮助,谢谢。

if条件应该写成..

 if compAI == ("1" or "2" or "3"):

在您的代码中,Python 解释器会将 "2""3" 视为 true。请注意,它没有根据 if 语句语法与 compAI 进行比较。