boxxboxy 语法

2024-10-02 02:44:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用一本书学习如何用pygame编写python代码,所以我要写下代码。但是当我运行它时,它在revealedBoxes[boxx][boxy]=True上给了我一个语法错误 ^
不知道是什么问题。如果你能帮忙,非常感谢

代码如下:

if boxx != None and Boxy != None:
        if not revealedBoxes[boxx][boxy]:
            drawHighlightBox(boxx, boxy)
        if not revealedBoxes[boxx][boxy] and mouseClicked:
            revealBoxesAnimation(mainBoard, [(boxx, boxy)]
            revealedBoxes[boxx][boxy] = True

Tags: and代码nonetrueifnotpygame语法错误
2条回答
            revealBoxesAnimation(mainBoard, [(boxx, boxy)]

你把括号掉在这里了

这是一个有效的声明

>>> revealedBoxes = [[True]]
>>> boxx, boxy = 0, 0
>>> revealedBoxes[boxx][boxy] = True

除非在whileif,…中用作表达式:

>>> if revealedBoxes[boxx][boxy] = True: pass
  File "<stdin>", line 1
    if revealedBoxes[boxx][boxy] = True: pass
                                 ^
SyntaxError: invalid syntax

>>> while revealedBoxes[boxx][boxy] = True: pass
  File "<stdin>", line 1
    while revealedBoxes[boxx][boxy] = True: pass
                                    ^
SyntaxError: invalid syntax

你是说==

>>> if revealedBoxes[boxx][boxy] == True: pass
...

更新

代码缺少)

        revealBoxesAnimation(mainBoard, [(boxx, boxy)]  # <  
        revealedBoxes[boxx][boxy] = True

相关问题 更多 >

    热门问题