Thanks for posting the question, we are glad to help you. Given the limited time, i could able to complete Function 4 and 5. Refer the screenshots for code indentation and output
Function 4
-------------------------------------------------------------------------------------------------------------------------------------
def is_map(map):
############################################
#1) it is a list of lists
if type(map) is list:
for row in map:
if type(row) is list:
continue
else:
return False
else:
return False
############################################
#2) it has at least one row and one column;
row_length=len(map)
col_length=len(map[0])
if row_length<1 or col_length<1:
return False
############################################
# it is a list of lists of values of type in
column_width=len(map[0])
for row in map:
# validates the width of each row is the same
if column_width==len(row):
pass
for col in row:
#4) only non-negative ints are present (zero and up is
accepted)
col=str(col)
if col.isdigit():
continue
else:
return False
else:
return False
############################################
# if it passes all the test
return True
print(is_map([[1,2,3],[0,1,5]]))
print(is_map([[[1,2,3,4],[5],[6,7]]]))
print(is_map([[-2,False, [1,2,3]], [4,5,6]]))
-------------------------------------------------------------------------------------------------------------------------------------
Function 5
------------------------------------------------------------------------------------------------------------------------------------
def neighbors(map, r, c):
rows=len(map)-1
cols=len(map[0])-1
if(r>rows or c>cols):
return []
start_row=0
end_row=0
start_col=0
end_col=0
if(r==0):
start_row=r
else:
start_row=r-1
if(r==rows):
end_row=r
else:
end_row=r+1
if(c==0):
start_col=0
else:
start_col=c-1
if(c==cols):
end_col=c
else:
end_col=c+1
index_list=[]
for row in range(start_row,end_row+1):
for col in range(start_col,end_col+1):
if row==r and col==c:
continue
index_list.append((row,col))
return index_list
print(neighbors([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]], 1, 1))
print(neighbors([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]], 0, 3))
print(neighbors([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]], 2, 0))
--------------------------------------------------------------------------------------------------------------------------------------
Image screenshot
Due to time constraint, i was not able to write code for 6 and 7. You, can follow the code for 4 and 5 and comeup with a solution for 6 and 7
thank you so much...........
PYHTON CODING FUNCTIONS HELP Part 2. Also need help with these last functions. Requirements/restraints and the...
1)def toggle_cell(row, column, cells): • Return value: Flip the cell in the column of row from alive to dead or vice versa. Return True if the toggle was successful, False otherwise. • Assumptions: o cells will be a two-dimensional list with at least one row and one element in that row. o row and column are index values of cells • Notes: o Cells is being edited in place. Note that the return value is a Boolean and not a...
I need help as quick as possible, thanks beforehand. Please provide the test output The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown below. 35 The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 - 9 exactly The sum of each row, each column and each diagonal all add up to the same number. This is shown below: 15 4 92 15 - 81 + 15 15 15...
Encoding and Decoding PPM image 3 & 4 are parts of question 2 Code for a09q1: We were unable to transcribe this image3 Encoding an Image in a09q2.py In the next four sections, you will no longer write class methods but rather functions. In each of the next four parts, you should be importing the PPM class from a09q1.py to use with the command from a09q1 import PPM Note that this is similar to how the check module was imported...
I need a python 3 help. Please help me with this question Part 2. Linked Lists You start working with the class LinkNode that represents a single node of a linked list. It has two instance attributes: value and next. class LinkNode: def __init__(self,value,nxt=None): assert isinstance(nxt, LinkNode) or nxt is None self.value = value self.next = nxt Before you start with the coding questions, answer the following questions about the constructor Valid Constructor or Not? LinkNode(1, 3) LinkNode(1, None) LinkNode(1,...
I only need the "functions" NOT the header file nor the main implementation file JUST the implementations for the functions Please help, if its difficult to do the complete program I would appreciate if you could do as much functions as you can especially for the derived class. I am a beginer so I am only using classes and pointers while implementing everything using simple c++ commands thank you in advanced Design and implement two C++ classes to provide matrix...
PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...
Write a C++ program to simulate a stream path. In this problem you can make the following assumptions 1. The elevation grid will be a n row, m column grid of integers, where n and m are constant. 2. Once the stream origin location is specified, then the stream flows to whichever of the four adjacent locations in the grid represents the largest descent. 3. If more than one of the adjacent locations have the largest descent, then the water...
Please help i need a C++ version of this code and keep getting java versions. Please C++ only Purpose: This lab will give you experience harnessing an existing backtracking algorithm for the eight queens problem, and seeing its results displayed on your console window (that is, the location of standard output). Lab A mostly complete version of the eight queens problem has been provided for you to download. This version has the class Queens nearly completed. You are to provide...
This is a python question. Write a function mult_table(n) that consumes a natural number n and returns the n+1 by n+1 multiplication table (where each entry in the inner list is equal to the product of which list it is and the inner list position number, or in other words, the product of the row and column numbers). Using accumulative recursion, no abstract list functions. def mult_table(n) ''' Returns the n+1 by n+1 multiplication table mult_table: Nat => (listof...
Need Part 1 and Part 2 please! also has to build and run, thank you! CSCI 40 Computer Programming Methodology I Assignment 16 Part l Write a program that declares a two dimensional array and initialize it with following integers 2 4 3 81 45 2 10 3 6 20 21 12 28-5 7 11 2 4 75041 8 5 -10 3 2 0 Then 1. Write statements that display all the numbers in the array 2. Write statements that...