Question
Python3, Please help me understand these functions. I have inclued previous functions that might need to be used. Thank you in advance! :) This is
Python3, Please help me understand these functions. I have inclued previous functions that might need to be used. Thank you in advance! :) This is all the functions that i have completed and are part of the project, the only function not completed is join_map_below which i have included as well.
def show(map): #OK mystr = '' substrings = [] maxlen = max([len(str(j)) for i in map for j in i]) for i in map: i = [' '*(int(maxlen)-len(str(j)))+str(j) for j in i] substrings.append(" ".join(i)) return " ".join(substrings) + ' ' def highest_point(map): #OK max = 0 row = 0 column = 0 for i in range(len(map)): for j in range(len(map[i])): if map[i][j] > max: max = map[i][j] row = i column = j if max == 0: return None else: return (row, column)
def on_map(map, r, c): #OK if (r >= 0 and c >= 0 and r = 0): #checking if the length of map is empty or not s = set() for i in range(len(map)): s.add(len(map[i])) for j in map[i]: if not isinstance(j, int): #checking for types return False elif j
def neighbors(map, r, c): #OK neighbors = [] for i in range(r-1, r+2): for j in range(c-1, c+2): if not (i==r and j==c): if i >= 0 and i = 0 and j
def water_adjacent(map, r, c): #OK if r >= 0 and r = 0 and c
def join_map_side(map1, map2): #OK if len(map1) != len(map2): return None else: result = [] for i in range(len(map1)): result.append(map1[i] + map2[i]) return result
def join_map_below(map1, map2): #3/5 failed tests 4,5 if len(map1) != len(map2): return None list = [] for i in map1: list.append(i) for i in map2: list.append(i) return list
def crop(map, r1, c1, r2, c2): #OK if not map: return [] if r1 = len(map): r2 = len(map) -1 if c2 >= len(map[0]): c2 = len(map[0]) -1 if r1 > r2 or c1 > c2: return [] else: result = [] for i in range(r1, r2 + 1): result.append(map[i][c1:c2 + 1]) return result
def flooded_map(map, rise): #OK newmap = [] x = 0 for i in map: newmap.append([]) for j in i: level = j - rise if level rise: map[i][j] = map[i][j] - rise else: map[i][j] = 0
def reorient(map): #OK row = len(map) col = len(map[0]) newmap = [] for i in range(col): newmap.append([]) for j in range(row): newmap[i].append(0) for i in range(row): for j in range(col): newmap[j][i] = map[row - 1 - i][j] return newmap
def find_land (map, r, c, dir): Given a map and location, as well as a direction to look (one of ["N", "NE","E", "SE", "S", "SW", "W", "NW"]), indicate how many spaces we must travel on the map to reach land. If we're on land, the answer is zero. If there's no land in that direction on this map, we return None. Assume: map is a map as defined above, r and c are int values, and dir is one of the strings above. find_land (map4,2,2, "S")- 2 find_land (map4,4,1, "NE")None * find_land(map5,7,e,"N")-5Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started