Question: Help!!! please write in python. I really need the answer today, please do the question quickly, thanks! The 1-dimensional Game of Life occurs on a

Help!!! please write in python. I really need the answer today, please do the question quickly, thanks!

Help!!! please write in python. I really need the answer today, pleasedo the question quickly, thanks! The 1-dimensional Game of Life occurs ona list of cells where each cell is either alive or dead.The population of cells evolves from one generation to the next accordingto three rules: 1. Any live cell survives into the next generationif it has 2 or 4 living neighbours in its 2-neighborhood (thecell itself does not count towards the number of living neighbors). 2.Any dead cell becomes alive in the next generation if it has

The 1-dimensional Game of Life occurs on a list of cells where each cell is either alive or dead. The population of cells evolves from one generation to the next according to three rules: 1. Any live cell survives into the next generation if it has 2 or 4 living neighbours in its 2-neighborhood (the cell itself does not count towards the number of living neighbors). 2. Any dead cell becomes alive in the next generation if it has 2 or 3 living neighbours in its 2-neighborhood. 3. All other live cells die and all other dead cells remain dead. The rules are applied to each cell simultaneously to compute the next generation of cells. The 2-neighborhood of a cell consists of the cell itself and its two neighbors to the left and two neighbors to the right of the cell (if those neighbors exist). The 2-neighborhoods for three different cells labelled i are shown in the figure below. Cells near the front or back of the list may have fewer than 5 cells in their 2-neighborhood. 2-neighborhood 2-neighborhood 2-neighborhood Complete the Python module named life1.py that provides functions useful for implementing the 1-dimensional Game of Life. At a minimum, the module should provide the following functions: make_cells(n, val) print_cells(cells) neighborhood(cells, index) evolve(cells) blinker(cells, index) You may add additional functions (such as a function that determines if a dead cell becomes alive in the next generation, or function that determines if an alive cell survives in the next generation) if you wish. It is strongly recommended that you complete the functions in the order that they are listed above. To help you test your work, the examples shown below are included in the starter code provided to you. You are strongly encouraged to write your own tests. Each function in your module should be documented using the convention described in the Week 05 Jupyter notebook Functions: Documentation. Each function is described below. make_cells (note that this function is already implemented for you) make_cells(n, val) : Returns a list of length n where all of the elements are equal to the boolean value val . Raises a ValueError if n is less than zero. Example c = life1.make_cells(5, False) should return the list [False, False, False, False, False] . print_cells print_cells(cells) : Prints a list cells where all of the elements of cells are equal to either True or False . Use # for True and - for False . Include a newline after printing the cells. Example # this is ex print_cells.py c = life1.make_cells(7, False) C[3] = True C[5] = True lifel.print_cells(c) lifel.print_cells(c) should print: ---#- #- ---#- #- neighborhood neighborhood (cells, index) : Returns a list containing the cells in the 2-neighborhood for the cell cells[index] . Raises a ValueError if index is less than zero. Example # this is ex_neighborhood.py c = lifel.make_cells(7, False) C[3] - True C[5] = True print('cells') life1.print_cells(c) print('neighborhood(s, 0)) n = life1.neighborhood(s, 0) lifel.print_cells(n) print('neighborhood(C, 1)') n = life1.neighborhood(C, 1) life1.print_cells(n) print('neighborhood(C, 3)') n = life1.neighborhood(s, 3) life1.print_cells(n) print('neighborhood(C, 6') n = life1.neighborhood (C, 6) life1.print_cells(n) should print: cells ---#- #- neighborhood(s, 0) neighborhood(C, 1) ---# neighborhood(s, 3) --#- # neighborhood(C, 6) - # - evolve evolve(cells) : Applies the rules of the 1-dimensional Game of Life to cells to get the next generation of cells. Replaces each cell in cells with the new generation. Raises a ValueError if cells is empty. Example # this is ex_evolve.py c = life1.make_cells(7, False) C[3] = True C[5] = True C[6] = True print('cells') lifel.print_cells(c) lifel.evolve(c) print('evolve') life1.print_cells(c) should print: cells ---#-## evolve ----## Explanation the first cell remains dead because it has 0 alive neighbors (in its 2-neighborhood) the second cell remains dead because it has 1 alive neighbor (in its 2-neighborhood) the third cell remains dead because it has 1 alive neighbor (in its 2-neighborhood) the fourth cell dies because it has 1 alive neighbor (in its 2-neighborhood) the fifth cell becomes alive because it has 3 alive neighbors (in its 2-neighborhood) the sixth cell remains alive because it has 2 alive neighbors (in its 2-neighborhood) the seventh cell dies because it has 1 alive neighbor (in its 2-neighborhood) Implementation note: The rules are supposed to be applied to all cells simultaneously but you cannot do this in Python. Practically, what this means is that you cannot change a value in cells until that value is no longer in the 2-neighborhood of any other cell that you need to update (e.g., you cannot change cells[0] until you have computed the results for cells[1] and cells[2] ). There are several different ways to deal with this problem, but the easiest solution is to first copy the elements of the list cells into a new temporary list and then use the temporary list for counting neighbors. You can then update the values in the list cells without issue. blinker blinker(cells, index) : Inserts a blinker pattern into the list cells with the pattern starting at cells[index] . Raises a when inserted at index. ValueError if index is less than zero or if the complete blinker pattern does not fit into cells The blinker pattern is made up of the six boolean values False, False, True, True, False, False All six values must fit into cells starting at cells[index] otherwise blinker(cells, index) will raise an exception. Example # this is ex_blinker.py C = life1.make_cells(12, False) print('cells') life1.print_cells(c) life1.blinker(s, 3) print('cells with blinker') life1.print_cells(c) for i in range(0, 10): lifel.print_cells(c) lifel.evolve(c) should print cells cells with blinker -## -#--# ##- ---------- -----## -------- -----## --------- ---## ---------- Q1.py - C:/Users/lucyz/Desktop/Q1.py (3.8.7) File Edit Format Run Options Window Help def make_cells (n, val): if n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!