Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON CODING HELP. part 1 :( Requirements/restraints for project is pictured in the screenshot. so is the map that is refeered to. For a project

PYTHON CODING HELP. part 1 :(

Requirements/restraints for project is pictured in the screenshot. so is the map that is refeered to. For a project I need to do these tasks

Function 1:

def show(map):

#given a map, create and return a string that when printed is formatted like the example (provided below) in a multi-line output containing only digits and spaces

function does not need to be called by any others, but is useful when testing other definitions manually)

values in the same row are separated by a single space

each value uses just enough characters for the LARGEST VALUE IN THE ENTIRE MAP, by using extra spaces to the left of any number that didnt take as many spaces to print. If everythings the same number of digits, we wouldnt need any of these extra spaces.

Each line ends with a digit from the last column, and then a newline, without any extra spaces.

Assume: map is a map as defined above.

Show ([[1, 2, 5], [ 10, 11, 8]]) --> 1 2 5 10 11 8

>>> print(show([[1, 2, 5], [ 10, 11, 8]]))

1 2 5

10 11 8

>>>

# 11 is the biggest number; it needs two columns to display, so all numbers need two

# characters in this case, single- digit numbers needed a single leading space.

Function 2:

def highest_point(map): Given a map, where is the highest point of land? If there is no land, return None. Otherwise, respond with a tuple of the row and column where we can find the highest point (dont use any negative indexes in answer). If there is a tie, return the location with the lowest row-index, and the lowest column-index as a further tie breaker. (the earlier row wins, and in further ties the earlier column wins).

Assume: map is a map as defined above

highest_point([[0, 0, 0], [0, 0, 0]] --> None

highest_point([[2, 5, 1], [9, 7, 6]] --> (1, 0) # row 1, column 0 has the highest land.

Highest_point([[1, 6, 1], [6, 2, 3]] --> (0, 1) # 6 is the highest land; first occurrence at (0, 1)

Function 3:

def on_map(map, r, c): Given a map and candidate location (the row/column indexes), is that position on the map? (remember, we only accept non-negative values for valid indexes).

Assume: map is a map as defined above, and r and c are int values.

on_map([[4,5,6],[7,8,9]], 0, 0) True # holds the value 4

on_map([[4,5,6],[7,8,9]], 2, 3) False # row too big; column too big

on_map([[4,5,6],[7,8,9]], -1, 1) False # no negatives allowed

image text in transcribed
image text in transcribed
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), st, 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! 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

Students also viewed these Databases questions

Question

7. Understand the challenges of multilingualism.

Answered: 1 week ago