Question: In TODO 5 , you will implement the simulate_infection function. The function has the following three parameters: population: An int specifying the total population of

In TODO 5, you will implement the simulate_infection function. The function has the following three parameters:

population: An int specifying the total population of the animals.

initial_infected: An int specifying the number of animals infected on day 1.

r_number: A float specifying the rate of spread of the infection (R number).

Based on the provided arguments, the function will print one or more lines, each of which displays two values - day number (starting from one) and current alive population - separated by a space.

Let us go over the details of how the function works using the following example arguments:

population: 1000000

initial_infected: 1000

r_number: 1.1

Overall, the simulate_infection function implements the loop that prints the state of the population each day. Note that the first row should show the full population, i.e., before any of the animals die. The last row should show 0. There should be exactly one row showing 0.

We suggest you implement the function in the following flow:

Assign two variables - one for the number of animals that are currently infected (e.g., infected), and the other for the number of animals that are already deceased (e.g., deceased). Using the example arguments the initial assignment would be 1000 for the infected and 0 for the deceased.

Print the day number (1), and the state of the population on the first day.

The state of the population can be computed as population - deceased (total deceased animals subtracted from the population). Hence, the first row in our specific case would be:

Define a loop that executes as long as there are any animals left by checking the state of the population. (Note that different solutions are possible. Calculating the total deceased and subtracting it from the population as a state of population (without changing the population) can be a solution. Alternatively, the deceased can be used for only the animals that get deceased for that day. In this case, the population can be decreased every day.) It depends how you manipulate the population and deceased variables.

Within each iteration:

Update the total number of deceased animals (deceased + infected).

Update the number of currently infected animals (infected * r_number). Note that only a whole number of animals can be infected. Hence, you have to use rounding. Always round up, i.e., 4.1 -> 5, 78.7 -> 79, etc. (consider the built-in functions such as round or ceil method from the math library. Consider different cases when choosing the function to use.)

Increment the day number by 1.

Print the day number, and the state of the populations on that day.

1 1000000 # the population is still unaffected on day 1 # there are infected animals but none of them died just yet 

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 Biology Questions!