Final exam — December 7

We know you can

You are ready now — For problem solving prowess — Your best will be shown


No looking back now


Problem solving


Important


Terminology


Helpful documenation



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


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 sequence s equals x; otherwise, False
x not in s False if an item of sequence s equals x; otherwise, True
s + t New concatenation of sequences s and t
s * n New sequence equivalent to adding sequence s to itself n times
s[ i ] ith item of sequence s
s[ : ] New copy of sequence s
s[ i : ] New copy of sequence s from index i up to and including last sequence element
s[ : j ] New copy of sequence s from index 0 up to but not including index j
s[ i : j ] New copy of sequence s from index i up to but not including index j
s[ i : j : k ] New copy of sequence s from index i up to but not including index j with step k
s.index( x ) Index of the first occurrence of item x in sequence s
s.index( x, i ) Index of the first occurrence of item x in sequence s at or after index i
s.count( x ) Total number of occurrences of item x in sequence s



Realizations





nbr = int( v )

nbrs = []

for v in s :

nbr = int( v )

nbrs.append( nbr )



little engine

Footnote

† Adapted in part from docs.python.org