Question: test plan for :# Write your count _ type function below: ( 2 marks ) # * * * * * * * * *

test plan for :# Write your count_type function below: (2 marks)
#********************************************
def count_type(map_data, map_type):
return sum(row.count(map_type) for row in map_data)
# Count the number of times map_type occurs in map_data
#********************************************
# Write your classify_map function below: (4 marks)
#********************************************
def classify_map(map_data):
total_cells = sum(len(row) for row in map_data)
if count_type(map_data, 'R')> total_cells/2:
return 'Suburban'
elif count_type(map_data, 'A')> total_cells/2:
return 'Farmland'
elif count_type(map_data, 'U')+ count_type(map_data, 'W')> total_cells/2:
return 'Conservation'
elif count_type(map_data, 'C')> total_cells/2 and 0.1<=(count_type(map_data, 'U')+ count_type(map_data, 'A'))/ total_cells <=0.2:
return 'City'
else:
return 'Mixed'
#********************************************
# Write your isolate_type function below: (2 marks)
#********************************************
def isolate_type(map_data, map_type):
return [[cell if cell == map_type else '' for cell in row] for row in map_data]
# Create a new list of lists where non map_type entries are replaced with ""
#********************************************
# Write your commercially_buildable function below: (2 marks)
#********************************************
def commercially_buildable(map_data, i, j):
if i ==0 or j ==0 or i == len(map_data)-1 or j == len(map_data[0])-1: # Check if the cell is not on the edge
return False
if map_data[i][j]!='U': # Check if the cell has map type U
return False
# Check adjacent cells for map types R and A
for di, dj in [(-1,0),(1,0),(0,-1),(0,1)]:
if map_data[i + di][j + dj] in ['R','A']:
return False
return True
# If all checks pass, the cell is commercially buildable return true

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!