Question: The code I have so far is: import random import math from matplotlib import pyplot as plt def normpdf(x, mean, sd): var = float(sd)**2 denom

The code I have so far is:

import random

import math

from matplotlib import pyplot as plt

def normpdf(x, mean, sd):

var = float(sd)**2

denom = (2*math.pi*var)**.5

num = math.exp(-(float(x)-float(mean))**2/(2*var))

return num/denom

recovery_time = 4

virality = 0.2

mean = 30

stdev = 1

class Cell(object):

def __init__(self,x, y):

self.x = x

self.y = y

self.state = "S" # can be "S" (susceptible), "R" (resistant = dead), or

# "I" (infected)

def process(self, adjacent_cells):

if self.state == 'I':

self.days_infected += 1

if self.days_infected == recovery_time:

self.state == 'S'

random_float = random.random()

if random_float

self.state = 'R'

if self.state == 'I':

for cell in adjacent_cells:

if cell.state == 'S':

random_number = random.random()

if random_number

cell.infect()

else:

return

def infect(self):

self.state= 'I'

self.days_infected = 0

class Map(object):

def __init__(self):

self.height = 150

self.width = 150

self.cells = {}

def add_cell(self, cell):

self.cells[(cell.x,cell.y)]=cell

def display(self):

image = []

cells=self.cells

for n in range(150):

j=[]

image.append(j)

for i in range(150):

j.append ((0.0,0.0,0.0))

# for h in range(self.height):

# for w in range(self.width):

# try:

# self.cells[str(h),str(w)]

# except KeyError:

# continue

#

for i in cells:

yb=(0.0,1.0,0.0)

if cells[i].state == 'S':

yb=(0.0,1.0,0.0)

#image[int(cells[i].x)][int(cells[i].y)]= (0.0,1.0,0.0)

elif cells[i].state == 'I':

yb=(1.0,0.0,0.0)

image[int(cells[i].y)][int(cells[i].x)]= yb

print(image)

plt.imshow(image)

def adjacent_cells(self,x,y):

list_adj_cells=[]

try:

list_adj_cells.append(self.cells(x+1,y))

except KeyError:

pass

try:

list_adj_cells.append(self.cells(x,y+1))

except KeyError:

pass

try:

list_adj_cells.append(self.cells(x-1,y))

except KeyError:

pass

try:

list_adj_cells.append(self.cells(x,y-1))

except KeyError:

pass

return list_adj_cells

m = Map()

def time_step(self):

for h in range(self.height):

for w in range(self.width):

try:

self.cells[(h,w)].process(self.adgacent_cells(h,w))

except KeyError:

pass

self.display()

def read_map(filename):

import csv

with open(filename) as f:

reader = csv.reader(f)

for row in reader:

x_coordinate= (row[0])

y_coordinate = (row[1])

c= Cell(int(y_coordinate), int(x_coordinate))

c.state = 's'

m.add_cell(c)

return m

j=read_map("nyc_map.csv")

j.display()

However, its giving me an error. The assignment is outlined in the picture. Help? Would really appreciate it if someone could fix the code for me pls! Thanks!

The code I have so far is: import random import math from

Edited question: The nyc_map.csv file is linked below (I couldn't upload the excel sheet to Chegg, so please follow the link and dowload the file, convert to .csv after download). Sorry for the inconvenience! Please let me know if there are any difficulties opening it.

https://docs.google.com/spreadsheets/d/1SRmpmuBu8UOqPyhkC1_iHFoTsMxSiSnuibHoPnrsjJc/edit?usp=sharing

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!