Class 42 — December 5
I say thanks to you — Your presence is a great gift — Brings me happiness
Look both ways
Agenda
- Take stock
Final
- If you are not taking the final Thursday @ 7 PM, see me at the start of class.
Want to be a CS 1112 TA in the spring
- Please fill out the departmental application
Survey
Thanks to the undergraduate TAs for making the course a success
- Jessica Emmons
- Eliott Kim
- Simone Olson
- Mark Panetti
- Ira Quint
- Chiara Sauvage
- Torian Wright
- Devon Yi
- Brittany Yu
- Lily Zamanali
Helpful documenation
- Module list
- Module dict
- Module random
- Module str
- Module pillow
- Module math
- Local module url
Imaging pattern
ow, oh = original.size # get dimensions of original
nw, nh = ... # determine dimensions of new image
new_image = Image.new( 'RGB', ( nw, nh ) ) # create new image
for nx in range( 0, nw ) : # fill in every pixel of new image
for ny in range( 0, nh ) :
nspot = (nx ,ny ) # set spot to be filled in new image
ospot = ... # determine corresponding spot in original
opixel = original.getpixel( ospot ) # get pixel at corresponding spot
npixel = ... # determine pixel for new image
new_image.putpixel( nspot, npixel ) # set spot in new image
return new_image # return filled in new image
Answer to questions about the test
- The test will cummulative.
- The test points are likely to be ~135.
- Questions can require in part familiarity with
- Fundamental types; e.g.,
int
,float
, andstr
- Arithmetic operators; e.g.,
+
,-
,*
,**
,/
,//
, and%
- Identifiers, keywords, variables, objects, values, and references
- Logical and relational operators;
and
,or
,not
,==
,!=
,<
,>
,<=
, and>=
- Control constructs; e.g.,
if
,for
, andwhile
- Nested
for
constructs
- Random value manipulation
random.seed()
random.randrange()
random.choice()
- Builtin-in functions; e.g.,
print()
,input()
,int()
,float()
,str()
,max()
,min()
,len()
,type()
, andid()
- URLs and web files; e.g., numeric, text and CSV contents
- Ranges
- Data structures and their use:
list
,dict
, tuples, methods and slicing
- Functions, parameters, definitions, and invocations
- Colors and PIL Image
List problems
- Sum the elements
- Check if every item in a list has a property
- Check if at least one item in a list has a property
- Find first / last index of an item with a property
- Accumulate a total
- Accumulate a sublist
- Compare two lists
- Synthesize two lists
Sequence expressions †
Operation Evaluation len( s )
Length of sequence s
min( s )
Smallest item of sequence s
max( s )
Largest item of sequence s
x in s
True
if an item of sequences
equalsx
; otherwise,False
x not in s
False
if an item of sequences
equalsx
; otherwise,True
s + t
New concatenation of sequences s
andt
s * n
New sequence equivalent to adding sequence s
to itselfn
timess[ i ]
i
th item of sequences
s[ : ]
New copy of sequence s
s[ i : ]
New copy of sequence s
from indexi
up to and including last sequence elements[ : j ]
New copy of sequence s
from index0
up to but not including indexj
s[ i : j ]
New copy of sequence s
from indexi
up to but not including indexj
s[ i : j : k ]
New copy of sequence s
from indexi
up to but not including indexj
with stepk
s.index( x )
Index of the first occurrence of item x
in sequences
s.index( x, i )
Index of the first occurrence of item x
in sequences
at or after indexi
s.count( x )
Total number of occurrences of item x
in sequences
Spring 2017 supplied code
Worth a 1000 words
Footnotes
† Adapted in part from docs.python.org