The lecture slides for Class 6 the code used, are available here: http://goo.gl/NWylEy

Homework (Please write if you need clarification or help)

1)

Reading: Exercise on slide 12 of Class6_spreadsheets2.pdf, See /code/analyze_imgdata5.py

2)

The guessing game programmed in the class (see: /code/python_game.py) has a bug – when you guess the correct number in the last trial, the program says, ‘You guessed right!’, and yet the program exists stating that ‘You lost! No soup for you!’, Identify where this bug is, and correct it.

3)

Write a program that takes a filename for input, and gives the following:

A) The number of words in this file.

B) The number of occurrences of ‘and’, ‘a’, ‘an’, and ‘the’ in the text.

C) Make a bar plot of values from B, with appropriate x labels, and file name as the plot title.

4)

On the meadows of Austria, live wild sheep, with no predators or external threats. The population of the sheep can takes values between 0.0 and 1.0 – representing the ratio between existing population and the maximum theoretical possible population.

The population of sheep, the next year is given by,

x(n+1) = R * x(n) * ( 1 – x(n) )

Where x(n) is the current year’s population.

Where R is a rate of reproduction.

The equation above incorporates, that the next years population depends on

– current years population (reproduction) when populations are small and

– over crowding (starvation) when population is reaching maximum possible population : theoretical “carrying capacity” of the environment.

Part1

Plot as points, the population (y axis) for the first 53 years (x axis). For the following cases:

(Subplot1) starting population = 0.2, R = 2.8, color = ‘k’

(Subplot1) starting population = 0.2, R = 3.3, color = ‘g’

(Subplot1) starting population = 0.2, R = 3.5, color = ‘b’

(Subplot1) starting population = 0.2, R = 3.8. color = ‘r’

(Subplot2) same as Subplot1, but with starting population = 0.4

(Subplot3) same as Subplot1, but with starting population = 0.6

(Subplot4) same as Subplot1, but with starting population = 0.8

Part2

For 300 random starting populations, find the population of sheep at the end of 87 years.

Make a plot for R (x-axis) versus population at the end of 87 years (300 points on Y-axis for each R value), when is R varying between 2.4 and 4 at a 0.01 resolution. [R = 2.4, 2.41, 2.42, … 3.99, 4.0]