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 look_(a)round.py
You first will implement a function to make a grid (2D list) of all o(single lower letter o character) of width (number of elements in each sublist) and height dimentions (number of rows).
# make_(g)rid(width, height)
my_(g)rid = make_(g)rid(9,9)
assert my_(g)rid ==[['o','o','o','o','o','o','o','o','o'],
['o','o','o','o','o','o','o','o','o'],
['o','o','o','o','o','o','o','o','o'],
['o','o','o','o','o','o','o','o','o'],
['o','o','o','o','o','o','o','o','o'],
['o','o','o','o','o','o','o','o','o'],
['o','o','o','o','o','o','o','o','o'],
['o','o','o','o','o','o','o','o','o'],
['o','o','o','o','o','o','o','o','o']]
To make sure you can see the result of modifications on your grid, write a print_(g)rid function to print each row of the grid:
my_(g)rid = make_(g)rid(9,9)
print_(g)rid(my_(g)rid)
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
Heres the main part of the problem: given a grid (2D 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 mark_(a)round because the idea is that you are marking the grid at (x, y) and around this position as well. The parameters for mark_(a)round are the grid, x (row), and y (position inside row).
my_(g)rid = make_(g)rid(9,9)
# mark_(a)round(grid, x, y)
mark_(a)round(my_(g)rid,4,4)
print_(g)rid(my_(g)rid)
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
['o','o','o','x','x','x','o','o','o']
['o','o','o','x','x','x','o','o','o']
['o','o','o','x','x','x','o','o','o']
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
['o','o','o','o','o','o','o','o','o']
You should write not only the mark_(a)round function, but another function that will be called inside mark_(a)round. This function should be called within_(l)imits and should return False and x or y are outside the limits of the grid. The parameters for within_(l)imits are the grid, x (row), and y (position inside row).
my_(g)rid = make_(g)rid(4,6)
assert within_(l)imits(my_(g)rid,-1,0)== False
assert within_(l)imits(my_(g)rid,0,0)== True
assert within_(l)imits(my_(g)rid,1,2)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!