函数会中断在i之后出现的所有代码

2024-04-24 17:04:06 发布

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

我开始做一个小游戏。我已经创建了一个函数,它会破坏它后面的所有代码。完整功能如下:

def printBoard(currentBoard):
#Prints out the game board
for x in range(5):
    #prints out 50 character line x
    print (' '.join(str(currentBoard[x*50:(x+1)*50]))

尽管它仍然适用于以下情况:

def printBoard(currentBoard):
    print (' '.join(str(currentBoard[x*50:(x+1)*50]))

甚至包括:

print("Hello")

之后就不行了。我试过切换变量名之类的,但是错误仍然存在。你知道吗


Tags: the函数代码功能boardgamedefout
2条回答

缩进错误,请将函数更改为:

def printBoard(currentBoard):
    #Prints out the game board
    for x in range(5):
        #prints out 50 character line x
        print (' '.join(str(currentBoard[x*50:(x+1)*50]))

看起来你错过了一个结束语“)”

相关问题 更多 >