Question: Going around in a point in a grid In this lab session we are going to focus on modularity. Name your file look _ (
Going around in a point in a grid
In this lab session we are going to focus on modularity.
Name your file lookaroundpy
You first will implement a function to make a grid D list of all osingle lower letter o character of width number of elements in each sublist and height dimentions number of rows
# makegridwidth height
mygrid makegrid
assert mygrid ooooooooo
ooooooooo
ooooooooo
ooooooooo
ooooooooo
ooooooooo
ooooooooo
ooooooooo
ooooooooo
To make sure you can see the result of modifications on your grid, write a printgrid function to print each row of the grid:
mygrid makegrid
printgridmygrid
ooooooooo
ooooooooo
ooooooooo
ooooooooo
ooooooooo
ooooooooo
ooooooooo
ooooooooo
ooooooooo
Heres the main part of the problem: given a grid D list of single characters and given coordinates x and y mutate the grid so that the coordinate and the positions around the coordinate hold the character x
Call your function markaround because the idea is that you are marking the grid at x y and around this position as well. The parameters for markaround are the grid, x row and y position inside row
mygrid makegrid
# markaroundgrid x y
markaroundmygrid
printgridmygrid
ooooooooo
ooooooooo
ooooooooo
oooxxxooo
oooxxxooo
oooxxxooo
ooooooooo
ooooooooo
ooooooooo
You should write not only the markaround function, but another function that will be called inside markaround This function should be called withinlimits and should return False and x or y are outside the limits of the grid. The parameters for withinlimits are the grid, x row and y position inside row
mygrid makegrid
assert withinlimitsmygrid False
assert withinlimitsmygrid True
assert withinlimitsmygrid
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
