Urgent help with the following question - make sure you look at 2b as well A mining company conducts a survey of an n-by
Posted: Fri Jul 01, 2022 5:43 am
Urgent help with the following question - make sure you look at2b as well
A mining company conducts a survey of an n-by-n square grid ofland. Each row of land is numbered from 0 to n-1 where 0 is the topand n-1 is the bottom, and each column is also numbered from 0 ton-1 where 0 is the left and n-1 is the right. The company wishes torecord which squares of this grid contain mineral deposits. Thecompany decides to use a list of tuples to store the location ofeach deposit. The first item in each tuple is the row of thedeposit. The second item is the column. The third item is anon-negative number representing the size of the deposit, in tons.For example, the following code defines a sample representation ofa set of deposits in an 8-by-8 grid.
deposits = [(0, 4, .3), (6, 2, 3), (3, 7, 2.2), (5, 5, .5),(3, 5, .8), (7, 7, .3)]
2a) Given a list of deposits like the oneabove, write a function to create a string representation for arectangular sub-region of the land. Your function should take alist of deposits, then a set of parameters denoting the top,bottom, left, and right edges of the sub-grid. Itshould return (do not print in thefunction) a multi-line string in which grid squares withoutdeposits are represented by "-" and grid squares with a deposit arerepresented by "X".
def display(deposits, top, bottom, left, right):"""display a subgrid of the land, with rows starting at top and uptobut not including bottom, and columns starting at left and up tobutnot including right."""ans = "" # delete this line and enter your own codereturn ans
For example, your function should replicate the followingbehavior for the example grid:
A mining company conducts a survey of an n-by-n square grid ofland. Each row of land is numbered from 0 to n-1 where 0 is the topand n-1 is the bottom, and each column is also numbered from 0 ton-1 where 0 is the left and n-1 is the right. The company wishes torecord which squares of this grid contain mineral deposits. Thecompany decides to use a list of tuples to store the location ofeach deposit. The first item in each tuple is the row of thedeposit. The second item is the column. The third item is anon-negative number representing the size of the deposit, in tons.For example, the following code defines a sample representation ofa set of deposits in an 8-by-8 grid.
deposits = [(0, 4, .3), (6, 2, 3), (3, 7, 2.2), (5, 5, .5),(3, 5, .8), (7, 7, .3)]
2a) Given a list of deposits like the oneabove, write a function to create a string representation for arectangular sub-region of the land. Your function should take alist of deposits, then a set of parameters denoting the top,bottom, left, and right edges of the sub-grid. Itshould return (do not print in thefunction) a multi-line string in which grid squares withoutdeposits are represented by "-" and grid squares with a deposit arerepresented by "X".
def display(deposits, top, bottom, left, right):"""display a subgrid of the land, with rows starting at top and uptobut not including bottom, and columns starting at left and up tobutnot including right."""ans = "" # delete this line and enter your own codereturn ans
For example, your function should replicate the followingbehavior for the example grid: