T-Th 9:05
or
T-Th 11:15
in Olin 155

CS 1110: Introduction to Computing Using Python

Spring 2015

The Lectures

The "HardCopy" 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 of the slides exactly as I use them in class. Use these for review. The "Python Demos" are .py modules that figure in the lecture. You are expected to download and play with these. A compact schedule for the whole semester showing lectures, labs, readings, due dates and prelim dates is available here.


Week 1


Week 1

22 January (Thursday): 1. Basics

Python Demos
Read All About It!
One Page Overview
ReadySetGo!
Printable Calendar
HardCopy
Slides
We start out using Python as a calculator, 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

27 January (Tuesday): 2. Modules and Scripts

Python Demos
KeyboardInput.py
ShowFormat.py
WindChill.py
Radius.py
Read All About It!
HardCopy
Slides
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. Mechanisms for input and output are discussed.


29 January (Thursday): 3. Conditional Execution

Python Demos
Abbreviator.py
Hyphenator.py
Read All About It!
HardCopy
Slides
Sometimes a condition has to be checked before heading into a computation. This requires an understanding of various “if” constructions. The Boolean type is introduced together with the and, or, and not operations. This will be an occasion to introduce the distinction between program structure and program flow.



Week 3

3 February (Tuesday): 4. Using and Building Simple Functions

Python Demos
simpleMath.py
ShowSimpleMath.py
Read All About It!
HardCopy
Slides
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 some of the functions from the math module. A simple module is used to show how to design your own functions. We start simple with functions that look like high school algebra math functions. The mechanics of function execution are detailed.


5 February (Thursday): 5. A Simple Graphics Module

Python Demos
simpleGraphics.py
ShowRect.py
ShowDisk.py
ShowStar.py
Tile.py
Read All About It!
HardCopy
Slides
We get more practice with functions by using a simple module that permits us to draw rectangles, circles and stars. These functions have multiple inputs and they do not return values (like the familiar trig functions). We will see how one function can call another function, how optional arguments work, and how ease-of-use can affect the design of the function inputs.



Week 4

10 February (Tuesday): 6. How Functions are Accessed and Work

Python Demos
Read All About It!
HardCopy
Slides
We use examples to lock in our understanding of how functions work. Call frames. Tracing execution. Flow of control. Arguments, parameters, and local variables. How one module can import the stuff in another module.


12 February (Thursday): 7. String Methods and For

Python Demos
ShowFor.py
Read All About It!
HardCopy
Slides
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 and introduce th econcept of iteration with the for statement



Week 5

19 February (Thursday): 8. Iteration: More For-Loops

Python Demos
ShowSqrt.py
Asteroid.py
Checkers.py
Read All About It!
HardCopy
Slides
Iteration is all about the idea of repeated calculation and is an absolutely essential part of the course. We have seen how for-loops can be used to ``walk down a string.'' Now we will see another version of the for-loop that can be used to manage more general iterations. 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.



Week 6

24 February (Tuesday): 9. Random Simulation

Python Demos
DiceRolls.py
MonteCarlo.py
Show_randint.py
Show_uniform.py
ShowNormal.py
Read All About It!
HardCopy
Slides
We introduce the random module and use some of its functions to solve interesting problems that involve random events. Estimating probabilities and averages is very important throughout science and engineering so we’ll get a good snapshot of how this is done.


26 February (Thursday): 10. While Loops

Python Demos
SqrtDemo.py
UpDownDemo.py
RW1.py
Read All About It!
HardCopy
Slides
Iteration is all about the idea of repeated calculation and is an absolutely essential part of the course. The while loop on of the key language constructions in this regard and it requires a rock solid understanding of Boolean expressions an ability to think iteratively. A numerical example (summation) and a string example (search) drive the discussion. With the while-loop in hand and an ability to write functions, we can address a whole new set of computational challenges.



Week 7

3 March (Tuesday): 11. More While

Python Demos
FibonacciDemo.py
Edges.py
Streak.py
Read All About It!
HardCopy
Slides
More practice with while via examples. We start out with Random Walks and Fibonacci numbers. We then look at a spiral problem where th e while loop turns off production when the spiral gets "too big." As an illustration of a search-for-the-first-occurrence problem, we look for "streaks" in a coin toss sequence.


5 March (Thursday): 12. Odds and Ends

Python Demos
ShowBreak.py
ShowTry.py
SqrtAssert.py
Read All About It!
HardCopy
Slides
We cover a collection of important topics that give us an excuse to review past ideas and anticipate what is coming up. These include the use of break, isinstance, try-except., and assertions. Discussion of math.floor, math.ceil, round, and int clarify the difference between type and value. The use of "in" and other little string slicing facts rounds out the lecture.



Week 8

10 March (Tuesday): 13. Prelim Review

Python Demos
Read All About It!
ClickerQ
Practice Prelim
Practice Prelim Sol


12 March (Thursday): 14. Lists

Python Demos
Read All About It!
HardCopy
Slides
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.



Week 9

17 March (Tuesday): 15. Lists and Functions

Python Demos
ShowSelect.py
PointCloud.py
Read All About It!
HardCopy
Slides
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.


19 March (Thursday): 16. More on Lists and Functions

Python Demos
MergePop.py
Read All About It!
HardCopy
Slides
More practice with void functions and references. Some basic ideas are reviewed: how to create a copy of a list, comparing lists with "is", vs comparing lists with "==", the idea of an alias. Two different implementations are given for a function that can merge two sorted lists into a single sorted list. of Merge are given.



Week 10

24 March (Tuesday): 17. Search and Sort

Python Demos
ShowSearch.py
ShowMergeSort.py
ShowBenchmarking.py
Read All About It!
HardCopy
Slides
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). We discuss efficiency and use the timit module to compare these two algorithms. Binary search illustrates the divide-and-conquer paradigm. So does the method of Merge Sort which we use to introduce the idea of recursion.


26 March (Thursday): 18. Recursion

Python Demos
ShowTriPartition.py
ShowMondrian.py
ShowFactorialR.py
simpleGraphicsE.py(Revised)
Read All About It!
HardCopy
Slides
We introduce recursion 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. Finally, we return our recursive implementation of merge sort that we developed in the previous lecture.



Week 11

7 April (Tuesday): 19. Introduction to Classes

Python Demos
ShowPointClass.py
ShowDeepCopy.py
Read All About It!
HardCopy
Slides
Introduction to classes and objects. Constructors. References. Attributes. Functions that return objects and that have object parameters. Lists of objects. Copy and DeepCopy.


9 April (Thursday): 20. Dictionaries

Python Demos
ShowDict.py
TheSonnets.txt
Read All About It!
HardCopy
Slides
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.



Week 12

14 April (Tuesday): 21. Methods and Classes

Python Demos
ShowBetterPoint.py
ShowSimpleDate.py
ClickerQ.zip
Read All About It!
HardCopy
Slides
Implementing methods. reasoning about method calls. Getters and Setters. Sorting a list of objects. Using isinstance.



Week 13

21 April (Tuesday): 23. More 2D Arrays

Python Demos
ShowCompany.py
Read All About It!
HardCopy
Slides
Some Lab Prob Sols
Classes with attributes that are 2D numpy arrays. More on subscripting, class invariants, and elementary operations with 2D arrays of data.


23 April (Thursday): 24. Working with Data Files and Numpy Graphics

Python Demos
ShowPyLab.zip
Read All About It!
HardCopy
Slides
We live in the era of Big Data, a phenomena driven by sensor technology and cheap memory. An important skill to have involves reading data from a file that has been downloaded from the Web, computing with that data on your computer, and then writing the results to another file. We step through this scenario thereby showing you how Python supports the process. All along the way there will be opportunities for you to build up your facility with string manipulation. Plotting a continuous function like y = sin(x) is a connect-the-dots exercise that involves a pair of lists: one for the x-values and one for the y-values. Using MatPloy 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 14

28 April (Tuesday): 25. Odds and Ends

Python Demos
ShowFract.py
Read All About It!
HardCopy
Slides
Operator overloading, more pylab and numpy


30 April (Thursday): 26. Inheritance

Python Demos
Cards.py
Read All About It!
HardCopy
Slides


5 May (Tuesday): 27. Three Great Examples

Python Demos
LastLecCodes
Read All About It!
HardCopy
Slides
Test Taking Tips
Post Pre2 Clicker Q's



Week 15


Course Material Authors: D. Gries, L. Lee, S. Marschner, C. Van Loan & W. White (over the years)