我正在尝试为游戏创建一个函数,但是我的身体出现了一些问题。我创建了一个函数,该函数使用函数的参数返回一个字符串。根据我的功能,我需要将board
(parameter1)行索引row_index
(Parameter2)中的字符作为单个字符串返回。
任何帮助将是有用的。泰
这是我的函数头和身体:打印棋盘排
def make_str_from_row(board, row_index):
""" (list of list of str, int) -> str
# Return the characters from the row of the board with index row_index
as a single string.
>>> make_str_from_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 0)
'ANTT'
"""
for i in range(len(row_index) - 1):
if board[i] row_index[i]
return board[i]
它是做什么的那一刻? –
@PeterWood:我的猜测是,由于怪异的if语句,它会抛出语法错误。 –
'row_index'是一个整数吗?你只能在序列上使用'len',比如列表。 'board'是一个列表。 –