多倫多大學(xué)CSC108Assignment2課業(yè)解析
多倫多大學(xué)CSC108Assignment2課業(yè)解析
題意:
按照功能描述完成8個函數(shù)逛腿,對矩陣進(jìn)行一定操作
解析:
3*3矩陣定義如下: THREE_BY_THREE = [[1, 2, 1], [4, 6, 5], [7, 8, 9]] 第一個函數(shù)compare_elevations_within_row(elevation_map: List[List[int]], map_row: int,level: int) -> List[int],接收三個參數(shù)分別是矩陣、要比較的行、要比較的值区端,compare_elevations_within_row(THREE_BY_THREE, 1, 5)即找到上述矩陣第一行权埠,比5小的數(shù)织阳、等于5的數(shù)和大于5的數(shù)杠人,并以列表形式返回,即[1, 1, 1]执泰;第二個函數(shù)把起點(diǎn)到終點(diǎn)元素之間(含起點(diǎn)和終點(diǎn))所有元素的值加上delta枕磁,若結(jié)果大于1保留修改否則取消;第三個函數(shù)和第四個函數(shù)都需要遍歷所有元素术吝,前者計(jì)算平均值计济,后者返回最大值的行列坐標(biāo)。
涉及知識點(diǎn):
python 列表排苍,函數(shù)
更多可+薇??討論 : qing1119X
"""Assignment 2 functions."""
from typing import List
THREE_BY_THREE = [[1, 2, 1], [4, 6, 5], [7, 8, 9]]
FOUR_BY_FOUR = [[1, 2, 6, 5], [4, 5, 3, 2], [7, 9, 8, 1], [1, 2, 1, 4]]
UNIQUE_3X3 = [[1, 2, 3], [9, 8, 7], [4, 5, 6]]
UNIQUE_4X4 = [[10, 2, 3, 30], [9, 8, 7, 11], [4, 5, 6, 12], [13, 14, 15, 16]]
def compare_elevations_within_row(elevation_map: List[List[int]], map_row: int, level: int) -> List[int]:
"""
? ? Return a new list containing the three counts:
? ? the number of elevations from row number map_row of elevation map elevation_map that are less than, equal to, and greater than elevation level.
? ? Precondition:
? ? elevation_map is a valid elevation map. 0 <= map_row < len(elevation_map).
>>> compare_elevations_within_row(THREE_BY_THREE, 1, 5) [1, 1, 1]
>>> compare_elevations_within_row(FOUR_BY_FOUR, 1, 2) [0, 1, 3]
"""
pass? # remove this line when you implement this function