Python Programming (Part 7): Exercise 2 - Storing population in a list

Ariel Rokem

(Stanford University)

Play Video

Duration: 9:41

Further Information:

Modify your code so that the values of n0, n1, n2, and n3 are stored in a list and not as separate individual variables. HINT: You can start off by declaring an empty list using the syntax n = [], and then append each new calculated value of nt to the list. Get the first and last values in the list, calculate their ratio, and print out “Grew by a factor of ” followed by the result.

Bonus: Extract the last value in two different ways: first, by using the index for the last item in the list, and second, presuming that you do not know how long the list is. Change the values of r and K to make sure that your cell still runs correctly and gives reasonable answers.




Created: Sunday, June 1st, 2014