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
- You must use my files for developing your solutions. For problems that involve module testing, the testers have been built-in into the module. The download files are available here.
- Some problems require developing code for image manipulation. The expected imagery is available here.
Important
- Do not leave the room without checking you uploaded all of your solutions. I regret that no post-exam solutions will be accepted.
- You are responsible for reading the test in its entirety.
- Based on your many past educational achievements, I expect you to do well on this test.
- Read each question both thoroughly and mindfully of what is being asked.
- To receive points, you must turn in your test.
Terminology
- Increment means add.
- Decrement means subtract.
- The additive inverse of a number x, is –x.
- The value of x / y is called a quotient.
- A number x is evenly divisible by a number y, if the remainder of x divided by y is zero. The % is the Python remainder operator.
- The terms dataset and table are synonymous. They are lists of lists. The standard view is they are lists of rows, where each row is a list of column values. The individual column values are called cells.
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
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
Realizations
- A variable has an identity and a type
- The value of a variable indicates where the object which it represents can be found
- Strings are immutable
- String functions require the use of a parameters
- String splitting
s.strip()
returns a new list of the words making ups
.
s.strip( '\n' )
returns a new list of the lines making ups
.
s.strip( ',' )
returns a new list of the comma-separated data cells making ups
.
- Converting string data to numeric data.
- To hand back a single integer value
nbr
from a single numeric representationv
nbr = int( v )
- To hand back a list of integer values
nbrs
from a string liststrings
nbrs = []
for v in s :
nbr = int( v )
nbrs.append( nbr )
- A function invocation cannot change the identity of an argument
- All functions return a value either explicitly or implicitly. If there is no explicit return,
None
is returned.
Footnote
† Adapted in part from docs.python.org