self.infection_rate=infection_rate

    defspread(self,population):

    new_population=[]

    forpersoninpopulation:

    ifnotperson.is_infectedandself.infection_rate>0:

    #计算是否感染

    ifrandom.random()

    person.is_infected=True

    new_population.append(person)

    returnnew_population

    #初始化人口

    population=[Person()for_inrange(1000)]

    #创建病毒实例

    flu_virus=Virus(infection_rate=0.05)

    #模拟病毒传播