COMP 200: Elements of Computer Science
Spring 2013

Assignment 3

Put all your answers in one CodeSkulptor file. Put text answers in Python comments. Use Python comments to clearly mark each problem number.

Work in assigned pairs on this assignment. Submit it on OWL-Space, under Assignment 3. Only the first person listed in the pair should submit the Codeskulptor URL. Put the pair designation as posted, (NetID1, NetID2), at the top of your submission as well as in Python comments at the top of your CodeSkulptor code. Including the person's actual names too would be nice.

Starting with this assignment, your grade will partly depend on your code style. For this assignment, we will begin to consider the following elements of code style.

Be sure to read the course policies.

Data structures (35 points total)

For the following problems, consider the three compound data structures that we have introduced so far: strings, lists, and tuples.

  1. (6 points)

    Describe the difference between mutation and assignment.

  2. (8 points)

    Which types are mutable?

  3. (10 points)

    For each mutable type, give code that illustrates the mutability, and briefly describe why this code in fact illustrates the property.

  4. (6 points)

    Which types can contain values of any other type.

  5. (5 points)

    Give an example of a list that contains a list, which itself contains a list.

Predator-prey modeling (65 points total)

Note that a version of plot_populations() using time steps is provided for you at the bottom of these notes. Use it, or equivalent code, as a starting point.

  1. (22 points total)

    Create a version of plot_populations() that also displays another plot. The x values show the hare population, and the y values show the lynx population.

    To create such a plot, you will also have to build a list containing the appropriate values.

  2. (5 points)

    Give an example call to plot_populations() where the hare and lynx populations not just fluctuate, but oscillate. I.e., they each repeat the same populations over and over.

    Note that with sufficient time steps to provide accuracy, all possible inputs should lead such oscillation, unless one or both populations die off.

    In the new second plot, you should see that the populations form a closed loop that repeats.

  3. (22 points)

    We would like to modify our model in an attempt to make it more realistic. We will assume that the land can support only so many hares. Above this cutoff, any excess hares will starve and die. However, hares will continue to give birth at the same rate. In other words, when the hare population is above the cutoff, the next time step's hare population will be that limit, plus any hares born, less any hares eaten.

    Create plot_populations_limit() that is like the previous version, but also takes an additional hare_limit parameter. Edit the code that updates the populations to obey the new rule.

  4. (6 points)

    Give an example call to plot_populations_limit() where the initial hare population is below this limit, but this new rule eventually effects the populations.

    Provide a similar call to plot_populations() with the same inputs (aside from the population limit, of course) for comparison.

  5. (10 points)

    Describe the overall effect of this population limit. How does it effect the shapes of the curves and the population values?