Question: DESPERATE NEED OF HELP - Can anyone help me answer the following question and make sure the multi-line string is returned, not printed? I really

DESPERATE NEED OF HELP - Can anyone help me answer the following question and make sure the multi-line string is returned, not printed? I really need the second part of the question answered too (6.2). I will make sure to reward those have provide answers and also give an upvote as well!

A mining company conducts a survey of an n-by-n square grid of land. Each row of land is numbered from 0 to n-1 where 0 is the top and n-1 is the bottom, and each column is also numbered from 0 to n-1 where 0 is the left and n-1 is the right. The company wishes to record which squares of this grid contain mineral deposits.

The company decides to use a list of tuples to store the location of each deposit. The first item in each tuple is the row of the deposit. The second item is the column. The third item is a non-negative number representing the size of the deposit, in tons. For example, the following code defines a sample representation of a 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)]

6.1. Given a list of deposits like the one above, write a function to create a string representation for a rectangular sub-region of the land. Your function should take a list of deposits, then a set of parameters denoting the top, bottom, left, and right edges of the sub-grid. It should **return** (do not print in the function) a multi-line string in which grid squares without deposits are represented by "-" and grid squares with a deposit are represented by "X".

For example, your function should replicate the following behavior for the example grid:

print(display(deposits, 0, 8, 0, 8)) ----X--- -------- -------- -----X-X -------- -----X-- --X----- -------X print(display(deposits, 5, 8, 5, 8)) X-- --- --X

def display(deposits, top, bottom, left, right): """display a subgrid of the land, with rows starting at top and up to but not including bottom, and columns starting at left and up to but not including right."""

ans = #This may be replaced with the code that you provide

return ans #this may also be replaced with the return statement based on the code provided

6.2. Next, complete the following function to compute the total number of tons in a rectangular sub-region of the grid.

def tons_inside(deposits, top, bottom, left, right): """Returns the total number of tons of deposits for which the row is at least top, but strictly less than bottom, and the column is at least left, but strictly less than right.""" # Do not alter the function header. # Just fill in the code so it returns the correct number of tons.

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 Databases Questions!