Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions