Post date: Nov 10, 2011 10:3:25 PM
Announcements
New Homework linked: CodingBat 3
Homework
Work on PopulationSim
Work on CodingBat 3
Lecture Outline: Part 2 of PopulationSim Part 2 and list processing functions
Consider Part 2 of project PopulationSim
class Environment stores 3 cities, the location of both resources (water and wood), a GraphWin object along with several Graphics object it will draw during a simulation
Demo the finished project
New thing: To slow the growing population by creating new Circles of increasing radii and drawing them, use time.sleep(seconds). Example use:
import time
for lcv in range(10, 0, -1):
print(lcv)
time.sleep(1.0)
print('Blast off')
List processing with numbers. Add some functions to ListFun.py, test with ListFunTest.py (see Code demos page for the two files)
def numEvens(list) to return the number of even ints in the given list.
numEvens( [4, 2, 2, 3] ) → 3
numEvens( [1, 2, 3] ) → 1
numEvens( [1, 3] ) → 0
numEvens( [] ) → 0
def doubleUp(list) to return a list that is twice as long as each element duplicated next to the original
doubleUp( [1, 2, 3] ) → [1, 1, 2, 2, 3, 3]
def eachOneOneMore(list1, list2)to return True if each element in list2 is exactly one more than the corresponding element (the element at the same index) in list1. If the sizes of the lists differs, return False
eachOneOneMore( [1, 2, 3], [2, 3, 4] ) → True
eachOneOneMore( [1, 2, 3], [2, 3, 5] ) → False
eachOneOneMore( [1], [2, 3] ) → False
eachOneOneMore( [], [] ) → True
Introduce new Homework (10pts): CodingBat 3 (Note: Nick calls lists arrays)
In-class activity, in teams of 2 or 3 please.