CSci 157 - Final Review


Exam Coverage: Zelle Chapters 1 - 11 (Ch. 9 is worthwhile but wasn't assigned) supplemented with chapters from ThinkCSPY, primarily what was assigned in the reading and homeworks, though there are useful examples and material in Chapters 1-9, 12-17.

The final exam is comprehensive, building on the fundamentals covered in Exams 1 and 2, so there may be questions about topics covered on those exams and other topics which use them:

Examples from lecture, in-class exercises, homeworks, labs, and the text will figure in the exam.
Working through code examples by hand is an important skill; the examples from Exam 2 will show up again in some form.

Sequences

The different sequence types are very important in Python programming: range, tuple, str, list. Recall that some sequence types are mutable while others are immutable, and the common functions that work on all types of sequences, such as len and max. Know the difference between shallow copy and deep copy and how to make deep copies, especially of lists.

Strings. We remember , right? Know the basics of strings (the <class str> type), using the slice operator, and common string methods.

Lists (single and nested). Know how to create, initialize, and build single or nested lists. Be able to use index variables to access data in a list (for example as in weatherData/WeatherClass). Understand how data is stored in rows and columns in a nested list structure (as the Connect-4 and CheckerBoard examples). Review programs from lab and homework assignments, including list methods such as append. Common operations on numerical data in lists including finding a value in a list, summing all the values in a list, averaging the values in a list.

Range.  How the range function works when given two or three arguments. Use with the list conversion operator and in definite loops.

Tuples.
For us, the main use of tuples was to return more than one value from functions, as in the raceway.py example. We also saw them used in assignment statements in a similar way.

Dictionary. Storing key/value pairs in simple and nested dictionary structures along with the common dict methods. Primary examples come from the Collections Activity and Chapter 12 of ThinkCS.

Nested Sequences

Processing nested sequences, especially nested lists, generally requires nested loops. For example, the code below accesses and sums all the values in a nested list. To check your understanding of the what each loop does, insert a print function after the outer for loop to print row. You could also print x each time through the inner loop. Or, visualize the execution at PythonTutor.com.

values = [ [1,2,3], [4,5,6], [7,8,9], [10,11,12] ]
sum = 0 for row in values:
    for x in row:      sum += x print(sum)

Reading and Writing Files

Know the basics of opening, reading from, writing to, and closing files. Since the data in the file is typically read in sequence, they are considered sequences and are often read using for loops.

There may also be questions about reading from the specific type of file known as Comma-Separated Values (CSV) which we used in Lab 14. How is the csv module used to quickly read and process this data? Know the code from Model 3 and be familiar with the last program (particularly the answers to each part of Question 20).

User-defined data types: class

The idea of class types that describe attributes and operations. Basic class design, object creation, constructors ( __init__ ) and method calls. We also have the concept of scope of variables within a class along with local variables in methods. Recall class variables such as the avagadro variable used in the Atom example (atom3.py). We covered the use of dunder methods such as __init__ in constructing new objects of class types, __str__ to convert objects to strings for output, the role of self in defining new instance variables, and using self to access variables and methods inside class definitions.

Inheritance

Know how we derive new classes from existing classes and use them in programs. Some terminology: base class (superclass) and derived class (subclass).

Know the two basic relationships between classes: inheritance and composition (the relationships IS-A and HAS-A) and class hierarchies.

Logistics

Question Sources. Some concept and coding questions may be derived from lab, homework exercises and examples given in the textbook and in lecture. You might read over some of the exercises at the end of sections and chapters that we covered in the text and at least think about how to solve them.

Questions? If at any time you find that you cannot do a problem or understand a concept or a how a question on a previous test should be solved, contact me by e-mail or during office hours, including most of the afternoon of Reading Day. Bring as many questions as necessary to clear up anything you can't figure out on your own.

Come Equipped. You may bring your own notes and textbook (no sharing).  No calculators, laptops, magnifying lenses needed or allowed for the final; caffeinated beverages okay.