Autofill Use Python code to write it! You will be implementing a tool called \"a
ID: 657390 • Letter: A
Question
Autofill
Use Python code to write it!
You will be implementing a tool called "autofill". You may be familiar with this tool from programs such as paint. You will be given a text file full of Xs and Os, looking like this:
The grid may be any size, but will always consist only of Xs and Os.
Autofill takes a given square, and if it is an X does nothing. If the square has an O in it, it changes the O to an X and autofills the square above, below, to the left, and to the right. An example run of the program:
Invalid inputs are permitted to crash your program. Your autofill function should be recursive. Indexing starts at 1.
Please help! Thanks!!!
Explanation / Answer
def autoFill(y, x, matrix,rows,columns):
if x < 0 or y < 0 or x >= columns or y >= rows:
return
if matrix[y][x] != '0':
return
if matrix[y][x] == 'X':
matrix[y][x] = 'x'
autoFill(x - 1, y, matrix,rows,columns)
autoFill(x + 1, y, matrix,rows,columns)
autoFill(x, y - 1, matrix,rows,columns)
autoFill(x, y + 1, matrix,rows, columns)
return matrix
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.