The Lectures
The "Handout" link connects to a printer friendly pdf of the lecture slides.
There are 6 slides per page and you may find it handy to bring a copy to class for note taking.
The "Slides" link will give you a pdf with one slide per page. It is sometimes the
case that we do not get through all the slides in lecture. Nevertheless, you are responsible for their
content.
Get all the lecture slides and handouts for the entire semester in one (24mb) download:
AllTheLectures.zip.
The "Python Demos" are .py modules that relate to the lecture material.
Many of these demos figure in the Lab exercises. Regardless,
you are expected to download, run, and understand these programs.
A compact schedule for the whole semester showing lectures, labs, readings,
due dates and prelim dates is available
here.
Week 1
28 January (Thursday): 1. The Assignment Statement and Types
We start out using Python as a calculator in what is called the interactive mode. The idea of a variable is
introduced and the dynamics of the assignment statement are detailed. Three basic types are illustrated
through examples: integers, floats, and strings.
Week 2
2 February (Tuesday): 2. Modules and Scripts
A module is a .py file that contains Python code. The easiest kind of module to understand simply houses a
sequence of statements called a script. Sample scripts that involve numbers and strings are used to solidify our
understanding of the assignment statement and types. Code in one module can ''import'' code from another.
Mechanisms for input and output are discussed.
4 February (Thursday): 3. Conditional Execution
Sometimes a condition has to be checked before heading into a computation and for that we need various
''if-else'' constructions. The Boolean type is introduced together with three logical operators: and, or, not.
We will see a distinction between program structure and program flow.
Week 3
9 February (Tuesday): 4. Modules and Functions
Modules can also house functions. Functions are packagings of important calculations that are typically used
over and over again. Experts design useful modules that can then be shared within the Python community. We
show how to import and use certain functions from the math module. A sample module is used to show
how to design your own functions. We with start simple examples that look like high school algebra math
functions. A function is built to compute square roots. The building process will highlight the connections between
algorithmic thinking and program implementation.
11 February (Thursday): 5. Introduction to Procedures Through Graphics
We get more practice with functions by using a module that supports the drawing rectangles, circles, and other
geometric shapes. These functions have multiple inputs and they do not return values like the square root function. We
show how one function can call another function, how optional arguments work, and how ease-of-use can
affect the design of a function inputs.
Week 4
18 February (Thursday): 6. How Modules and Functions Work
We use examples to lock in our understanding of how functions work. Topics include call frames, tracing
execution, arguments, parameters, and local variables. Regarding the use of modules we discuss the logic behind
the import command, global variables, and the ''dot'' notation.
Week 5
23 February (Tuesday): 7. String Methods
In object-oriented programming, functions and the data that they manipulate are packaged in classes. We
become acquainted with this idea by practicing with the built-in string class. In this context, the functions are
referred to as methods. We get practice with various string methods such as count, find, and replace. The ''in''
operator is introduced and we uplift our ability to ''think Boolean'' by practicing with various Boolean-valued
methods that relate to strings.
25 February (Thursday): 8. Iteration with Strings
Iteration is all about the idea of repeated calculation and it is an absolutely essential part of the course. We show
how for-loops can be used to ''walk down a string'' processing each character in turn. With this capability we can
solve problems that would otherwise be out of our reach. For example, we need the loop construction if we are to
count the number of digits in a given string or if we are to reverse the order of its characters.
Week 6
1 March (Tuesday): 9. Iteration Using the range Function
We revisit the sqrt function and use a for loop to handle the rectangle averagings. We show how to draw an n
by-n checkerboard. Summation problems and find-the-min problems provide instructive examples. We introduce
the random module and use some of its functions to execute interesting simulations that involve random events.
Estimating probabilities and averages is very important and we provide a snapshot of how this is done.
3 March (Thursday): 10. While Loops and Random Walks
Sometimes the number of required iterations is not known in advance. This motivates the notion of a while-loop.
We use random walk simulation to showcase important ideas associated with the interplay between iteration and
functions.
Week 7
8 March (Tuesday): 11. Iteration with While
More examples of while-loop iteration.
We use the square root computation and other examples to illustrate the key ideas. Practice will be important
because the design of a while loop requires a heightened level of Boolean thinking.
10 March (Thursday): 12. Logical Maneuvers
It is time to uplift our Boolean expertise (again). We illustrate the value of using boolean variables when processing
situations that have a complicated logic. We revisit the idea of a boolean-valued functions. The debugging
importance of using assertions to check preconditions and postconditions. How to raise and handle exceptions
through the try-except construction.
Week 8
15 March (Tuesday): 13. Prelim Review
StudyTip. Recreate an exam situation by giving yourself 90 minutes for the practice prelim.
Do it with books/notes/laptops closed.
The other pdf is not quite a full prelim, but it is made up of actual exam questions. Remember that some exam
questions are tightly coupled to
assignment problems. That is why some of these old questions had to be tweaked so that they are doable. We will make solutions available Sunday night, 3/13. Do not bother looking at old Fall semester
prelims--they are too different to be useful.
17 March (Thursday): 14. Lists of Numbers
There is a way to package a sequence of numbers (or strings) into a single entity and that entity is called a list.
List thinking requires a facility with subscripts, not unlike what we saw with strings. The for-loop is particularly
handy for organizing certain list computations that involve iteration. A function can have a parameter that is a
list, but the "interactions" require a new (and tricky) type reasoning that we review through examples. The
distinction between void methods and fruitful methods is made. Our examples show that a function can return
more than one thing and that loops can be nested.
Week 9
22 March (Tuesday): 15. Lists of Strings
Two examples are considered that highlight various aspects of functions
that have list parameters and/or return lists. Computing the diameter of a cloud of points is
look-for-the-maximum problem that involves nested loops. A pair of float lists that house the x and y coordinates of the points
is involved in the computation
The Python map function is introduced. The second example concerns selection sort.
Through this example we become acquainted with void functions and how they can modify a list in the callin program even though they do
not return anything. It is all about references to list objects.
24 March (Thursday): 16. Lists Are Objects
Right now we can say that an object is a packaging of data together with methods that can act on it. Strings are
objects and we have played with various string methods. Lists are objects and we have played with some of the
subtleties associated with functions that have list parameters. We are gradually ramping up for a serious trip into
object-oriented programming. Now is the time to get clear on the notion of a reference to an object. A reference
can be thought of as something that ''points'' to an object, a kind of address. It is distinct from the object itself.
This sounds simple but it takes a while to get used to the idea. Two variables x and y can actually refer to the same
object and you will be sorry if you disregard that possibility! Spending time on how to make copies of objects and
what goes on when an object is created helps. We use the perfect shuffle as an example.
Week 10
5 April (Tuesday): 17. Dictionaries
Yet another way to organize data in Python is with a "dictionary". Whereas lists and strings are indexed with
integers, e.g., x[4] = 10, dictionaries are indexed with "keys", e.g., x{'NY'} = 'Albany'. This can simplify many
text-based computations. We show how to assemble a word frequency dictionary with data coming from a text file
encoding of Pride and Prejudice. All along the way we remember that dictionaries are objects.
7 April (Thursday): 18. Introduction to Classes
Classes enable us to create types of our own design. The data that ''feeds into'' a computation is often structured
with interconnections that are handy to maintain. Once we define a class we can use to create objects that package
the data according to our design. Constructors are special methods that do this. We illustrate the key ideas with a
class called Point that can be used to represent a point like (3,4). The ''3'' and the ''4'' are packaged to form a unit
which we refer to as a Point object. We develop a method that can be used to compute the distance
between two points, a method that can be used to rotate a point about the origin, and method that can be used to
reflect a point across the 45-degree line. We use graphics to demonstrate the success of our implementations. We
show how to write functions that have Point objects as inputs and Point objects as outputs.
Week 11
12 April (Tuesday): 19. Lists of Objects
To illustrate how we can use a list of objects to solve an interesting problem we define a class called Disk that can
be used
to package the center point and radius. We develop a Boolean-valued method that can be used to determine if two
disks intersect. By using a list of disk objects we proceed to display a collection of randomly generated disks
that are distinct from one another. A second example involves census data. We define a class called County that
provides a handy way to encode the name of a county, the corresponding state, and its population in 2010, 2011,
2012, 2013, and 2014. We then create a list of such objects based on data that is read from a US census text file.
We show how to sort such a list based on (for example) the 2014 population and then print out the ten
biggest counties based on that result.
14 April (Thursday): 20. More Complicated Class Constructions
We develop a
class called Fraction that supports computations like (2/3) +(4/5) = (22/15) and (2/3)*(6/7)=(4/7). The example highlights
the idea of operator overloading.
We design a second class called SimpleDate that can be used to represent dates like ''7/4/1776''. It includes a method that can be used to compute
the number of days between two dates. Another method takes a ''current'' date and an integer n and then
computes a SimpleDate object that represents a date is n days into the future. Class
variables and class invariants are important features of the SimpleDate example.
Week 12
19 April (Tuesday): 21. Recursion
We are totally familiar with the idea of one function (or method or procedure) calling another. Can a function call
itself and what exactly does that mean? The answer is ''yes'', a function can call itself and the idea is called
recursion. Recursion is not an easy topic but it deserves a place in our course because is so very important. Indeed,
life as we know it would be very different were it not for a handful of breakthrough recursive functions.
We introduce the idea via two graphics procedures that do interesting ''divide-and-conquer'' tilings. One deals
with triangles and the other with rectangles. A recursive implementation of the factorial function is used to
illustrate the mechanics behind recursive function execution.
21 April (Thursday): 22. Searching a List
Searching a list for a particular value is a fundamental computation of great importance. We discuss linear search
(for arbitrary lists) and binary search (for lists that have been sorted). The efficiency of the two algorithms is
compared using a ''stop watch'' to measure execution time. How long a function requires to do its thing typically
depends on the volume of input data. For example, on average it would 100 times longer for linear search to find
an item in a length two million list as it would in a length twenty thousand list. On the other hand, finding a name in
the Manhattan phone does not take 1000 times longer than finding a name in an Ithaca phone book. We show why.
Week 13
26 April (Tuesday): 23. Prelim 2 Review
Prelim 2 syllabus: A5, A6, Lab 6, Lab 7, L ab 8, Lab 9, and all lecture
material through the lecture of Thursday April 14. (Note: part of that lecture was actually
delivered on April 19.)
28 April (Thursday): 24. Sorting a List
There are many ways to sort a list of numbers from little to big. These same methods can be applied to
alphabetizing a list of strings. We compare the method of selection sort and the method of merge sort. It turns out
the latter approach is a ''divide and conquer'' approach that lends itself to a recursive implementation. This means
that we will get more experience with recursive thinking and with computational settings that require the careful
management of multiple lists.
Week 14
3 May (Tuesday): 25. Inheritance and Other Important OOP Ideas
The idea of building on one another's work is fundamental
throughout science, engineering, and business. When it comes to computing,
how can I take a class that someone has implemented and then add functionality
to it? Python supports ''inheritance'' and that makes it possible to gracefully
build on existing software. It is an essential feature of object oriented programming.
Other frameworks that support good software engineering are discussed such
as accessing attributes through getter and setter function and the idea of overriding a method.
5 May (Thursday): 26. Numpy Arrays and Plotting
Plotting functions is a connect-the-dots
exercise that involves a pair of lists: one for the x-values and one for the y-values. Using the pyplot module we get
practice doing this. The exercise is rich in object-oriented computing so we will have many opportunities to
improve our skills in that arena as well. Being able to produce beautiful plots and illuminating displays of data
is an essential skill in many disciplines.
Week 15
10 May (Tuesday): 27. Two Dimensional Arrays
We all have experience with tables of data with their rows and columns of information. In Python the two
dimensional array can be used to house this arrangement. Their construction and manipulation requires a
heightened facility with subscripts. We introduce key features of the numpy.py module which is widely used
and very friendly when it comes to 2D array computations. We get more practice with subscripting, class invariants, and
elementary operations with 2D arrays of data.
|