Python 为什么即使条件为真,循环也会中断?

Python 为什么即使条件为真,循环也会中断?,python,Python,我用python中的字典制作了一个简单的Tic-Tac-Toe游戏,它可以自动处理python中的枯燥内容。当条件匹配时,while循环应该中断。但它一直在继续 我尝试用“或”替换“和”操作符,循环在第一次运行时中断。怎么了?如果条件满足,为什么循环不平衡 这些条件应该与或相关联,而不是和,因为你可以通过连续做出任意3个来赢得tic-tac-toe。与和一起,每3行必须相同 它在第一个回合后结束的原因是,您没有检查单元格是否已实际填充。因此,空的行、列或对角线将被视为匹配,因为所有的空格都是相

我用python中的字典制作了一个简单的Tic-Tac-Toe游戏,它可以自动处理python中的枯燥内容。当条件匹配时,while循环应该中断。但它一直在继续

我尝试用“或”替换“和”操作符,循环在第一次运行时中断。怎么了?如果条件满足,为什么循环不平衡



这些条件应该与
相关联,而不是
,因为你可以通过连续做出任意3个来赢得tic-tac-toe。与
一起,每3行必须相同

它在第一个回合后结束的原因是,您没有检查单元格是否已实际填充。因此,空的行、列或对角线将被视为匹配,因为所有的空格都是相等的

与其只是检查它们是否相等,不如检查它们是否相等于
turn

    if(    theBoards['A'] == theBoards['B'] == theBoards['C'] == turn
        or theBoards['D'] == theBoards['E'] == theBoards['F'] == turn
        or theBoards['G'] == theBoards['H'] == theBoards['I'] == turn
        or theBoards['A'] == theBoards['D'] == theBoards['G'] == turn
        or theBoards['B'] == theBoards['E'] == theBoards['H'] == turn
        or theBoards['C'] == theBoards['F'] == theBoards['I'] == turn
        or theBoards['A'] == theBoards['E'] == theBoards['I'] == turn
        or theBoards['C'] == theBoards['E'] == theBoards['G'] == turn):

这些条件应该与
相关联,而不是
,因为你可以通过连续做出任意3个来赢得tic-tac-toe。与
一起,每3行必须相同

它在第一个回合后结束的原因是,您没有检查单元格是否已实际填充。因此,空的行、列或对角线将被视为匹配,因为所有的空格都是相等的

与其只是检查它们是否相等,不如检查它们是否相等于
turn

    if(    theBoards['A'] == theBoards['B'] == theBoards['C'] == turn
        or theBoards['D'] == theBoards['E'] == theBoards['F'] == turn
        or theBoards['G'] == theBoards['H'] == theBoards['I'] == turn
        or theBoards['A'] == theBoards['D'] == theBoards['G'] == turn
        or theBoards['B'] == theBoards['E'] == theBoards['H'] == turn
        or theBoards['C'] == theBoards['F'] == theBoards['I'] == turn
        or theBoards['A'] == theBoards['E'] == theBoards['I'] == turn
        or theBoards['C'] == theBoards['E'] == theBoards['G'] == turn):

您应该使用
。您不希望所有这些条件都是
True
。但是,大多数条件在第一次移动后都会得到满足,因为除了一个位置之外,其他所有位置都是
'
。您应该使用
。您不希望所有这些条件都是
True
。但是,大多数条件在第一次移动后都会得到满足,因为除了一个位置之外,其他所有位置都是
'