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 list. o Row and column might not be valid indexes of cells ▪ Hmmm… what might be useful to use here?
• Examples:
toggle_cell(0, 0, [[1,1],[1,1]]) → True
toggle_cell(-1,0, [[1,1],[1,1]])→ False
2) def is_valid(row, column, cells):
• Return value: True if the row and column are valid indexes of cells, False otherwise • Assumptions: o cells will be a two-dimensional list with at least one row and one element in that row. ▪ No inner lists will be empty. o For the purposes of this function (and project,) negative index values are considered invalid. • Notes: The tests for this function are hidden.
• Examples:
is_valid(0,0,[[0,0,0], [0,0,0]]) → True
is_valid(3,3,[[0,0,0], [0,0,0]]) → False
is_valid(-1,0,[[0,0,0], [0,0,0]]) → False
python help please
do it python programming language
Solution to 1:
def toggle_cell(row, column, cells):
if row >= 0 and column >= 0 and row <= len(cells) - 1 and column <= len(cells[0]) - 1:
if cells[row][column] == 0:
cells[row][column] = 1
else:
cells[row][column] = 0
return True
else:
return False
print(toggle_cell(0, 0, [[1, 1], [1, 1]]))
print(toggle_cell(-1, 0, [[1, 1], [1, 1]]))
Output:
Solution to 2:
def is_valid(row, column, cells): if row >= 0 and column >= 0 and row <= len(cells) - 1 and column <= len(cells[0]) - 1: return True else: return False print(is_valid(0, 0, [[0, 0, 0], [0, 0, 0]])) print(is_valid(3, 3, [[0, 0, 0], [0, 0, 0]])) print(is_valid(-1, 0, [[0, 0, 0], [0, 0, 0]]))
Output:
1)def toggle_cell(row, column, cells): • Return value: Flip the cell in the column of row from...
def snake (grid, row, co1): Implement a function to calculate the longest "snake" of ones that can be made from a starting position in a grid. A snake is made by moving right and down from a starting position as far as possible. o Assumption: grid will be at least 1x1, row and col will each be valid indexes in grid o Restrictions: You may not use the max() or min) functions. o Examples: (cells is a 2D list below)...
You must use recursion to solve each problem. You cannot use loops in this homework. You cannot import any module. A couple of the tasks have individual restrictions; note them, as we will remove points for any task that does not follow the requirements. def factorial_evens(num): Implement a function to calculate and return the product of all even numbers from 1 up to num (inclusive if num is even). o Assumption: num will be an integer greater than or equal...
python function will Return True if string x contains 3 vowels in a row, in consecutive locations, false otherwise. assuming that 'vowels' refer to the following lowercase lttrs: a,e,i,o,u programs fails partially, only allowed to use float, str, int, appen, split, strip, len, range def vowels_three(x): for i in range (o, len(x), 2): if x[i] not in ('a,e,i,o,u'): return False return True
Finish each function python 3 LList.py class node(object): """ A version of the Node class with public attributes. This makes the use of node objects a bit more convenient for implementing LList class. Since there are no setters and getters, we use the attributes directly. This is safe because the node class is defined in this module. No one else will use this version of the class. ''' def __init__(self, data, next=None): """ Create a new node for...
/** * A collection of methods related to multi-dimensional arrays. */ public class Array2Lab { /** * Return whether k is in list. * Precondition: the elements of list are not null. * @param list the array to be searched. * @param k the number to search for. * @return true if k is an element of list, and false otherwise. */ public static boolean contains(Object[][] list, Object k) { return false; } /** * Create a String that...
PYTHON -------------------------------------------------------- class LinkedList: def __init__(self): self.__head = None self.__tail = None self.__size = 0 # Return the head element in the list def getFirst(self): if self.__size == 0: return None else: return self.__head.element # Return the last element in the list def getLast(self): if self.__size == 0: return None else: return self.__tail.element # Add an element to the beginning of the list def addFirst(self, e): newNode = Node(e) # Create a new node newNode.next = self.__head # link...
1. Please fill in the cells according to the given statements for each row. If the statement runs correctly, it returns true or false, in this case please state the output in the fourth column. If the statement gives an error (i.e. compile or runtime error), please indicate that by typing the corresponding column (2nd or 3rd column). For each item, please write a one-sentence explanation. Note that each row will contain only one result. (15 points in total) }...
Python code. NO importing modules. you may not use: contains(), index(), sum(),join(), split(). def column_cipher(plaintext): • Parameter(s): plaintext ----- a string; the message to be encrypted • Return value: A string; the ciphertext after applying the column cipher algorithm • Assumptions: o The standard English alphabet is used: "abcdefghijklmnopqrstuvwxyz" o All strings will be non-empty, entirely lowercase, and only contain valid letters in the alphabet. • How it works: o First, transpose the text into 5 different columns by writing...
Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elements. which are called eernents (or components). The elements of an (m × n)-dimensional matrix A are denoted as a,, where 1im and1 S, symbolically, written as, A-a(1,1) S (i.j) S(m, ). Written in the familiar notation: 01,1 am Gm,n A3×3matrix The horizontal and vertical lines of entries in a matrix are called rows and columns, respectively A matrix with the...
Python question class LinkNode: def __init__(self,value,nxt=None): assert isinstance(nxt, LinkNode) or nxt is None self.value = value self.next = nxt Question 2.1. Empty Node In some cases in it convenient to have a notion of an empty linked list. Usually it means that the linked list does not have any elements in it. In order to keep things simple (for now) we will assume that the list is empty, if it has a single node and its value is None. Add...