Python For/If语法错误

0 python syntax for-loop if-statement

这是我的代码:

for i in tuples:
    if i[0] == "U_shape":
        pieces.append(U_shape(i[1], boardLength, i[2])
    if i[0] == "I_shape":
        pieces.append(I_shape(i[1], i[2])
    if i[0] == "L_shape":
        pieces.append(L_shape(i[1], boardLength, i[2])
    if i[0] == "T_shape":
        pieces.append(T_shape(i[1], boardLength, i[2])
    if i[0] == "X_shape":
        pieces.append(X_shape(i[1], boardLength, i[2])
Run Code Online (Sandbox Code Playgroud)

这是错误:

if i[0] == "I_shape":
                    ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

Tho*_*mas 9

您在每个调用的行上都缺少右括号pieces.append.


Hug*_*ell 5

pieceType = {
    "U_shape": U_shape,
    "I_shape": I_shape,
    "L_shape": L_shape,
    "T_shape": T_shape,
    "X_shape": X_shape
}

pieces = [pieceType[a](b, boardLength, c) for a,b,c in tuples]
Run Code Online (Sandbox Code Playgroud)