This exam will focus on newer material but is comprehensive with regard to fundamentals covered in the first exam:
for
and while
str
,
list
, tuple
, and
filesdictionary
and its operationsExamples from lecture, homeworks, labs, and the text may figure in the exam. Homework and Activity solutions are posted on BrightSpace.
There are several operations we've used that are common to the various
sequence types (str
, list
, tuple
)
and each has its own specific operations.
str |
upper, lower, split, join and the
operators +, etc. |
list |
append, insert, remove, clear, copy |
tuple
|
count, |
common operations | Operators: len(...), the splice operator :, the indexing
operator [] see also https://docs.python.org/3/library/stdtypes.html#common-sequence-operations |
Understand how to define new functions using def
,
use of parameters, return statements, and local variables. Know how we
call functions, passing actual arguments to the call and how those
parameters are (implicitly) assigned to the parameters in the parameter
list. Variables defined inside a function are local to that
function and are not defined outside the function; this is why we use
parameters and return values to communicate data between functions.
Know for
and while
iteration
statements and when to use them. Be able to use and explain the Initialize-Test-Update
method for designing correct while loops. Be able to say how many times a
given loop will iterate, what an infinite loop is, and how to tell if a
loop terminates. Be able to explain why one style of loop might be
preferred in a given situation. Examples included summations, input
validation, and animation. See the relevant homework problems and more
examples from the Loop Practice
worksheet.
Some of our examples of using for
loops used
sequences, dictionaries, and range
. Be able to use
simple methods and operations (such as append
, the
indexing operator []
, slices (:
),
etc.) on sequence data in a loop.
The split
method for strings can also be very useful.
For the loops in each function defined below:
Number 1: The hailstone function implements the mathematical process at the heart of the Collatz Conjecture, which is a fairly straightforward yet unsolved problem in mathematics.
def hailstone():Number 2: Prints the first 18 numbers in the Fibonacci sequence.
def fibonacci():
"Computes and prints the first n Fibonacci numbers" newfib = 1 oldfib = 1 print(oldfib, ", ", newfib)
for k in range(1, 17): fib = newfib + oldfib oldfib = newfib newfib = fib print(fib)
Also, be able to convert loops like the one in fibonacci
to a while
loop, and be able to explain why while
loops like the one in hailstone
can't be
converted to a for loop.
Use of structured data such as lists nested inside another list to model
data such as: game boards, matrices, calendars (lists of dates), and so
on. Access/modification of individual elements using nested loops.
See the Nested Structured activity.
Storing key/value pairs in both simple and nested dictionary structures
(type <class 'dict'
>). Primary examples come
from the Collections Activity and
ThinkCS Section 11.7.
Use of dictionary methods such as keys
, values
,
and items
.
Know the definitions of cohesion
and coupling (from Art
in Computer Programming) and think about how they apply to
program, module, and function design.
The basic ideas and terminology from the Object-Oriented Programming
handout may be covered.
If at any time you find that you cannot do a problem or understand a concept or how a question on a previous test should be solved, contact me. Bring as many questions as necessary to clear up anything you can't figure out on your own.
There will be coding questions based on reading programs and there will be questions that require you to write short programs. These could feature anything covered.
You may bring your own notes and handouts (no sharing). No calculators, laptops, magnifying lenses, or iPhones needed or allowed; caffeinated beverages okay. I assume you can do high school math computations on paper.