如何访问由单独定义定义的变量中的整数

2024-05-23 22:31:04 发布

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

目前我正在处理的部分要求我从吧台上取出彩色的棋子,并把它们放在一块板上。你知道吗

我必须通过makeBoard来定义board,值存储在“myBoard”中

我正在挣扎的是,在我的下一节“enterPiece”中,我得到了它,所以我成功地从栏中取出了相关的彩色片段,从数字中减去它,然后将片段分配给董事会。。你知道吗

我的目标是。。0<;aPoint<;=n(其中n是我在makeBoard中定义的板的大小),但我不知道如何让python从变量myBoard获取n

def enterPiece(aBoard, aColour, aPoint):
    c = aBoard
    if 0 < aPoint:
        for j in range(aPoint):
            c.removePieceFromPoint(aColour, 0)
            c.addPieceToPoint(aColour, aPoint)
            return True
        else:
            return False

Tags: ltboardreturn定义数字彩色董事会棋子
1条回答
网友
1楼 · 发布于 2024-05-23 22:31:04

看起来nBoard.size,所以您应该能够重写为:

def enterPiece(aBoard, aColour, aPoint):
    c = aBoard
    if 0 < aPoint <= aBoard.size:
        for j in range(aPoint):
            c.removePieceFromPoint(aColour, 0)
            c.addPieceToPoint(aColour, aPoint)
            return True
        else:
            return False

相关问题 更多 >