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 elevation
map
elevation_map.
Precondition: elevation_map is a valid elevation map.
Every elevation value in elevation_map is unique.
>>> find_peak(UNIQUE_3X3)
[1, 0]
>>> find_peak(UNIQUE_4X4)
[0, 3]
"""
pass # remove this line when you implement this function
SOURCE CODE IN PYTHON:
def find_peak(elevation): #method to find and return cell with
max elevation
#setting first cell to max
maxRow=0
maxCol=0
#iterating through all the cells
for row in range(len(elevation)):
for col in range(len(elevation[row])):
#checking if current cell elevation is more than temporary
max
if elevation[row][col]>elevation[maxRow][maxCol]:
maxRow=row
maxCol=col
return [maxRow,maxCol] #return result
#testing method
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]]
print(find_peak(UNIQUE_3X3))
print(find_peak(UNIQUE_4X4))

OUTPUT:

using Python --- from typing import List THREE_BY_THREE = [[1, 2, 1], [4, 6, 5], [7,...
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:...
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...
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. >>>...
Python: P2 Write a function that reverses a python list using recursion (Chapter 6-3 in our textbook) E.g.: Input: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Constraints: - List elements are integers - The function should return a reversed array, not print its elements You may use the following code as template: def reverse(my_list, index = None): # your code here
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:...
Please use python. You can import only: from typing import Dict, List from PIL import Image import random Questions are: --------------------------------------------------------------------------------------------------------------------------------- 1. def rotate_picture_90_left(img: Image) -> Image: """Return a NEW picture that is the given Image img rotated 90 degrees to the left. Hints: - create a new blank image that has reverse width and height - reverse the coordinates of each pixel in the original picture, img, and put it into the new picture """ ----------------------------------------------------------------------------------------------------------------------------------- 2. def...
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.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):...
How to remove all occurrences of 2 from list2. Then display the list. Python import random list1 = [] for i in range (10): list1.append(random.randint(1,4)) print('List 1:') print(list1) list2 = [] list2.append(list1[5:]) print('List 2:') print(list2) list2.remove ******** (This is the part I am having trouble on!!) print('List 2 with all 2s removed:') print(list2) Sample output: List 1: [4, 1, 1, 3, 3, 3, 2, 4, 2, 4] List2: [3, 2, 4, 2, 4] List 2 with all 2s removed: [3,...
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...