Question

from typing import List THREE_BY_THREE = [[1, 2, 1], [4, 6, 5], [7, 8, 9]] FOUR_BY_FOUR...

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 get_average_elevation(elevation_map: List[List[int]]) -> float:
"""Return the average elevation across all cells in the elevation map
elevation_map.

Precondition: elevation_map is a valid elevation map.

>>> get_average_elevation(UNIQUE_3X3)
5.0
>>> get_average_elevation(FOUR_BY_FOUR)
3.8125
"""

pass # remove this line when you implement this function

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE IN PYTHON:

#Return the average elevation across all cells in the elevation map elevation_map.
def get_average_elevation(elevation_map):
total=0 #to store total of all elevations
count=0 #to store count of cells
#iterating through all the cells
for row in range(len(elevation_map)):
for col in range(len(elevation_map[row])):
total+=elevation_map[row][col] #adding elevation to total
count+=1 #incrementing count of cells
return total/count #returning average

#testing method
UNIQUE_3X3=[[1,2,3],[9,8,7],[4,5,6]]
FOUR_BY_FOUR=[[1,2,6,5],[4,5,3,2],[7,9,8,1],[1,2,1,4]]
print(get_average_elevation(UNIQUE_3X3))
print(get_average_elevation(FOUR_BY_FOUR))

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
from typing import List THREE_BY_THREE = [[1, 2, 1], [4, 6, 5], [7, 8, 9]] FOUR_BY_FOUR...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using Python --- from typing import List THREE_BY_THREE = [[1, 2, 1], [4, 6, 5], [7,...

    using Python --- 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 find_peak(elevation_map: List[List[int]]) -> List[int]: """Return the cell that is the highest point in the...

  • from __future__ import annotations import random from typing import TYPE_CHECKING, List, Any from course import sort_students...

    from __future__ import annotations import random from typing import TYPE_CHECKING, List, Any from course import sort_students if TYPE_CHECKING: from survey import Survey from course import Course, Student def slice_list(lst: List[Any], n: int) -> List[List[Any]]: """ Return a list containing slices of <lst> in order. Each slice is a list of size <n> containing the next <n> elements in <lst>. The last slice may contain fewer than <n> elements in order to make sure that the returned list contains all elements...

  • can you finish implementing the functions below ********************************************************************************************************** import urllib.request from typing import List, TextIO #...

    can you finish implementing the functions below ********************************************************************************************************** import urllib.request from typing import List, TextIO # Precondition for all functions in this module: Each line of the url # file contains the average monthly temperatures for a year (separated # by spaces) starting with January. The file must also have 3 header # lines. DATA_URL = 'http://robjhyndman.com/tsdldata/data/cryer2.dat' def open_temperature_file(url: str) -> TextIO: '''Open the specified url, read past the three-line header, and return the open file. ''' ... def avg_temp_march(f:...

  • List of Indexes Complete the following function. Note that neither item List nor index list should...

    List of Indexes Complete the following function. Note that neither item List nor index list should be mutated 1 from typing import List 3 def find value indexes (iten list: list. index List: Listint). V: object) + List[int]: may appear multiple times in iton list. index list contains zero or more indexes. Return a list of the indexes from index list at which v appears in ite list. Precondition: the values in index_list are valid indexes in its list. >>>...

  • from __future__ import annotations from typing import Any, Optional class _Node: """A node in a linked...

    from __future__ import annotations from typing import Any, Optional class _Node: """A node in a linked list. Note that this is considered a "private class", one which is only meant to be used in this module by the LinkedList class, but not by client code. === Attributes === item: The data stored in this node. next: The next node in the list, or None if there are no more nodes. """ item: Any next: Optional[_Node] def __init__(self, item: Any) ->...

  • Python 1 import matplotlib.pyplot as plt 2 import numpy as np 3 4 abscissa = np.arange(20) 5 plt....

    python 1 import matplotlib.pyplot as plt 2 import numpy as np 3 4 abscissa = np.arange(20) 5 plt.gca().set_prop_cycle( ’ color ’ , [ ’ red ’ , ’ green ’ , ’ blue ’ , ’ black ’ ]) 6 7 class MyLine: 8 9 def __init__(self, * args, ** options): 10 #TO DO: IMPLEMENT FUNCTION 11 pass 12 13 def draw(self): 14 plt.plot(abscissa,self.line(abscissa)) 15 16 def get_line(self): 17 return "y = {0:.2f}x + {1:.2f}".format(self.slope, self.intercept) 18 19 def __str__(self):...

  • Let U = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), A = (1,...

    Let U = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), A = (1, 3, 5, 7, 9), 8 (2, 4, 6, 8, 10), and C (1, 2, 3, 4, 5, 10). List the elements of each set. (Enter your answers using roster notation. Enter EMPTY or for the empty set.) (a) 4 {2, 4, 6, 8, 10) (Đ) 1 0 0 {2,4, 10) X (1) cuc {}

  • ONE_TEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Demonstrate replacing values with...

    ONE_TEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Demonstrate replacing values with the larger of their neighbors and demonstrate shifting to the right replacing the furthermost element with the first element in the list. data = list(ONE_TEN) def replaceNeighbors(data): for i in range(len(data)): if data[i] < data[i+1]: data[i] == data[i+1] replaceNeighbors(data) print("After replacing with neighbors: ", data) data = list(ONE_TEN) def shiftRight(data): data= data[-1] + dta[:-1] shiftRight(data) print("After shifting right: ", data) im having trouble with...

  • Complete the methods from random import randint class Spinner: """A spinner for a board game. A...

    Complete the methods from random import randint class Spinner: """A spinner for a board game. A spinner has a certain number of slots, numbered starting at 0 and increasing by 1 each slot. For example, if the spinner has 6 slots, they are numbered 0 through 5, inclusive. A spinner also has an arrow that points to one of these slots. === Attributes === slots: The number of slots in this spinner. position: The slot number that the spinner's arrow...

  • def _merge(lst: list, start: int, mid: int, end: int) -> None: """Sort the items in lst[start:end]...

    def _merge(lst: list, start: int, mid: int, end: int) -> None: """Sort the items in lst[start:end] in non-decreasing order. Precondition: lst[start:mid] and lst[mid:end] are sorted. """ result = [] left = start right = mid while left < mid and right < end: if lst[left] < lst[right]: result.append(lst[left]) left += 1 else: result.append(lst[right]) right += 1 # This replaces lst[start:end] with the correct sorted version. lst[start:end] = result + lst[left:mid] + lst[right:end] def find_runs(lst: list) -> List[Tuple[int, int]]: """Return a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT