I joined a course to learn programming with Python. For a certain assignment we had to write the code which I have pasted below.
This part of the code consist of two functions, the first one being make_str_from_row and the second one being contains_word_in_row. As you might have noticed the second function reuses the first function. I already have passed the first function but I cannot pass the second one because when it has to reuse it gives an error about the first function, which is confusing because I did not get any errors for my first function. It says that global variable row_index is not defined.
By the way the second function has been given in a starter code so it cannot be wrong. I don't know what's wrong, especially because I have passed the code which presumable has to be wrong.
I tried asking the team for some feedback in case it might be some error in the grader but it has been a week and I have had no reply while the deadline is 2 days away. I am not asking for answers here I only would like to ask somebody for an explanation about the given error so I can figure out a solution myself. I would really appreciate the help.
def makestrfromrow(board, rowindex):
""" (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'
"""
string = ''
for i in board[row_index]:
string = string + i
return string
def boardcontainswordinrow(board, word):
""" (list of list of str, str) -> bool
Return True if and only if one or more of the rows of the board contains
word.
Precondition: board has at least one row and one column, and word is a
valid word.
>>> board_contains_word_in_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 'SOB')
True
"""
for row_index in range(len(board)):
if word in make_str_from_row(board, row_index):
return True
return False
_(underscore) is relevant.makestrfromrowsure is a long-winded way to say"".join(board[rowindex])...