【问题标题】:Syntax for testing multiple conditions in a single if statement in python 3.6 using spyder IDE使用 spyder IDE 在 python 3.6 中的单个 if 语句中测试多个条件的语法
【发布时间】:2018-12-24 21:29:57
【问题描述】:

我正在尝试设计一个井字游戏并设计了一个测试获胜条件的函数。编译器在 if 语句的右括号中抛出错误无效语法。有人可以帮忙,因为我还是一个新手.

def win_check(board, marker,position):
    board[position] = marker
    if((board[9]=='X' and board[6] =='X' and board[3] == 'X') or
       (board[8]=='X' and board[5] =='X' and board[2] == 'X') or
       (board[7]=='X' and board[4] =='X' and board[1] == 'X') or
       (board[7]=='X' and board[8] =='X' and board[9] == 'X') or
       (board[4]=='X' and board[5] =='X' and board[6] == 'X') or
       (board[1]=='X' and board[2] =='X' and board[3] == 'X') or
       (board[1]=='X' and board[5] =='X' and board[9] == 'X') or
       (board[7]=='X' and board[5] =='X' and board[1] == 'X') or
       ):
        print("Player choosen X is winner")
        break()

multiple conditions in single if statement

【问题讨论】:

    标签: python-3.x if-statement spyder multiple-conditions


    【解决方案1】:

    您的if 条件以or ): 结尾。这是无效的,因为or 后面必须跟一个表达式。删除最后一个or

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-13
      • 1970-01-01
      • 2015-01-20
      • 1970-01-01
      • 2021-03-07
      • 2011-09-12
      • 2019-03-01
      相关资源
      最近更新 更多