PLEASE USE PYTHON LANGUAGE For this project, we will be implementing a tool call
ID: 657185 • Letter: P
Question
PLEASE USE PYTHON LANGUAGE
For this project, we will be implementing a tool called "autofill". Some of 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:
OOOOOOXOOOO
OOOOOXOOOOO
OOOOXOOOOOO
XXOOXOOOOOO
XXXXOOOOOOO
OOOOOOOOOOO
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:
Please enter a filename: input.txt
OOOOOOXOOOO
OOOOOXOOOOO
OOOOXOOOOOO
XXOOXOOOOOO
XXXXOOOOOOO
OOOOOOOOOOO
Please enter a square to fill, or q to exit: 1, 1
XXXXXXXOOOO
XXXXXXOOOOO
XXXXXOOOOOO
XXXXXOOOOOO
XXXXOOOOOOO
OOOOOOOOOOO
Please enter a square to fill, or q to exit: 6, 1
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
Please enter a square to fill, or q to exit: 4, 3
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
XXXXXXXXXXX
Please enter a square to fill, or q to exit: q
Invalid inputs are permitted to crash your program. Your autofill function should be recursive. Indexing starts at 1.
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 matrixRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.