Question: PYTHON CODING HELP. Lastly, these last functions. Need help with the following tasks. Map that may b referred to is in screenshot & so are
PYTHON CODING HELP. Lastly, these last functions. Need help with the following tasks. Map that may b referred to is in screenshot & so are restrictions & restraints.
Function 8:
def on_ridge(map, r, c): Given a map and a location, is that spot on a ridge? We define a ridge as a place that has two neighbors on opposite side that are both land and both lower than the spot itself. We consider sideto-side, above-and-below, as well as opposing diagonal neighbors as ways to show we are on a ridge. When the adjacent spot is off the map, it can't be used to claim we're on a ridge. If (r,c) isn't on the map, the answer is False.
Assume: map is a map as defined above, and r and c are int values.
on_ridge(map1,2,2) True
on_ridge(map6,1,3) False
on_ridge(map6,1,4) True
Function 9:
def is_peak(map, r, c): Given a map and a location, is it land and are all neighboring land spots lower than it? If the spot isn't on the map, it is not a peak. It's possible to have peaks on the border.
Assume: map is a map as defined above, and r and c are int values.
is_peak(map2,1,3) True
is_peak(map2,2,3) False
is_peak(map5,3,3) True
Function 10:
def join_map_side(map1, map2): Given two maps, create and return a new map by deep-copying map1 and map2 side by side for a longer map of the same height. If their heights don't match, return None.
Assume: map1 and map2 are maps as defined above. Remember, you must not modify the original maps.
join_map_side([[1,2],[5,6]], [[3,4],[7,8]]) [[1,2,3,4],[5,6,7,8]]
join_map_side([[1],[2],[3],[4]], [[5],[6],[7],[8]]) [[1,5],[2,6],[3,7],[4,8]]
join_map_side(m1,m2) None
Function 11:
def join_map_below(map1, map2): Given two maps, create and return a new map by deep-copying map1 and map2 one above the other for a taller map of the same width. If their widths don't match, return None.
Assume: map1 and map2 are maps as defined above. Remember, you must not modify the original maps.
join_map_below([[1,1],[2,2]], [[3,3],[4,4]]) [[1,1],[2,2],[3,3],[4,4]]
join_map_below([[1]], [[2]]) [[1],[2]]
join_map_below([[1,2],[3,4]], [[5,6,7,8]]) None
Function 12:
def crop(map, r1, c1, r2, c2): Given a map and two locations, create and return the map that only contains rows from r1 to r2 (inclusive), and columns from c1 to c2 (inclusive). If r1>r2 or c1>c2, the answer has no rows/columns (we return []). Similar to how slicing works, if more rows or columns are requested than exist, just return the parts that do exist. Remember, you must not modify the original map.
Assume: map is a map as defined above, and r1, r2, c1, and c2 are int values.
crop(map1,1,1,3,3) [[1,1,1],[1,3,1],[1,3,1]]
crop(map5,3,1,3,4) [[3,5,12,4]]
crop(map2,1,1,90,90) [[0,0,10,0,0,1],[0,1,3,1,1,1]]
crop(m1,2,2,1,3) []
Background The purpose of this assignment is to practice building, inspecting, and modifying 2D lists effectively. This often requires nested for-loops, but not always. It involves thinking of the structure like an N x M matrix of labeled spots, each with a row-and column-index. As before, we are restricting ourselves to the most basic functionalities, and any others that you want, you should implement yourself. Two-dimensional lists aren't conceptually more difficult than single-dimension lists, but in practice the nested loops, aliasing, and more complex traversals and interactions merit some extra practice and thought Project Basics document (part of assignment): http://cs.gmu.edu/-marks/112/projects/project basics,pdf Project Four tester file: http://cs.gmu.edu marks/112/projects/tester4p.py Grading Code passes shared tests: We11-commented/submitted: 1 TOTAL: 90 100 +5 extra credit What can I use? You may only use the following things. You may ask about adding things to a list, but we are unlikely to add anything. If you use something disallowed, it's not an honor code violation, you just won't get points for any tests that use them. Restrictions no modules may be imported. you may only use built-in functions and methods explicitly listed below in the allowed section. list comprehensions and lambdas may not be used on this project Allowed basic statements, variables, operators, del, indexing, slicing, in, are all allowed any form of control flow we've covered is allowed (if else, loops, etc) only these built-in functions: range), len(), int), str, type(), list) only these built-in methods: s.split), s.join(), s.pop), xs.append(), xs.extend() xs.insert(), s.format() on extra credit: xs.sort() method (only when indicated!) calling other functions of the project (and your own defined helper functions). Please do this! e Hint In our solution, we only used range, len, type, pop(), and .append(). (And.sort() just on the extra credit as directed by the instructions). Remember: your grade is significantly based on passing test cases-try to completely finish individual functions before moving on. The easiest way to implement many functions is to call the earlierleasier functions, so it'll pay off to complete functions before trying others. Don't let yourself be "kind of done" with a function, but miss all the tests
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
